Monday, October 27, 2008

Re: Loading components from actions

No, it does not work for components that take use of startup()
shutdown() or initialize()

Sure, there will be worse bottlenecks, but why not solve this one now
instead of later?

I have created a ComponentLoaderComponent that will do my bidding for
the meantime.

I am assuming cake has no built in commands to load components on run-
time then. I have created a ticket for this.

Thanks for your help (*not being sarcastic)

On Oct 27, 3:10 pm, teknoid <teknoid.cake...@gmail.com> wrote:
> Have you tried to use it? Does it work? Does it do what you need?
>
> ... as far as best practices go, it's best to build something and then
> worry about optimization.
>
> I assure you that you'll run into a lot more interesting and demanding
> issues before you get to the point where the bottleneck of your
> application will depend on when/where your Email component is
> instantiated.
>
> On Oct 27, 5:52 pm, "Turnquist, Jonah" <poppity...@gmail.com> wrote:
>
> > Erm... yes that will work, kind of, but then initialize(), startup()
> > and shutdown() will not be called in the component (at least I don't
> > see how they could... am I wrong?).
>
> > I did not do any speed tests, but I would not like components to be
> > instantiated unless needed (for instance what if the email component
> > had a very heavy startup() method?  I am trying to develop good
> > practices).
>
> > My code seems more logical this way.  Here is a pseudocode code
> > example
>
> > register action:
> > --if registration data validates {
> > ----save user
> > ----load email component
> > ----send email to confirm given email address
> > --}
>
> > This way the email component is not loaded until the app is 100% sure
> > it will even be sure.
>
> > ...unless maybe cake will handle this potential speed problem for me
> > in some way I can not imagine? I am in doubt but anyone is free to
> > inform me.
>
> > On Oct 27, 2:35 pm, teknoid <teknoid.cake...@gmail.com> wrote:
>
> > > Well, it does... but did you remember to:
> > > $email = new EmailComponent; ?
>
> > > p.s. what "speed reasons" did you run into?
>
> > > On Oct 27, 5:21 pm, "Turnquist, Jonah" <poppity...@gmail.com> wrote:
>
> > > > I've come across a need to load a component via the action for speed
> > > > reasons.
>
> > > > My case:
> > > > I have a user controller with view(), login(), and register()
> > > > actions.  I need the email component in, and only in, the register()
> > > > action.  So using var $components = array(etc); is not something I
> > > > want to do for speed reasons.  I do not want the component loaded for
> > > > actions that do not use it.
>
> > > > Looking at the docs it looks like this should work:
> > > > App::import('Component', 'Email');
>
> > > > But it doesn't. (??)
>
> > > > So how can this be done?
>
> > > > Thanks,
> > > > Jonah
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: