Just to clarify, this is something I saw on Teknoid's site (and, I think the idea was attributed to Gwoo or Nate). Basically, if there are lots of models needed for just one action (an Admin's index page, to show some site stats, in my case), it's more efficient to use ClassRegistry. Or, so I understand.
And, for sure, you'd want to assign it to a variable if it's required for more than a single call in the action. No sense bothering ClassRegistry again. On Mon, Jan 12, 2009 at 3:46 AM, _k10_ <[email protected]> wrote: > > To add more to Brians method, it would be a good practise to set the > model instance to a variable (who's name is the name of the Model) if > you plan to use the model more than once. > > $this->Member = ClassRegistry::init('Member'); > $this->set('new_members', $this->Member->getNewMembers()); > > _k10_ > > On Jan 10, 8:57 pm, brian <[email protected]> wrote: >> Based on something I saw on Teknoid's blog, I have this in my Admin index(): >> >> $this->set('new_members', >> ClassRegistry::init('Member')->getNewMembers()); >> $this->set('new_publications', >> ClassRegistry::init('Publication')->getNewPublications()); >> ... >> >> Apparently, this is the most efficient way to do it. From what I >> gather from the source, I'd say so. >> >> On Sat, Jan 10, 2009 at 7:08 PM, Miles J <[email protected]> wrote: >> >> > In one of my controllers, I use nearly 10-15 models. The problem is >> > that I dont need all these models, each model is respective to a >> > certain action and loading all these models seems like it would be >> > heavy and load slowly. >> >> > So I tried doing many variations of this in the action: >> >> > $this->uses = 'Friend'; >> > $this->uses[] = 'Friend'; >> > $this->uses = array('Friend'); >> >> > But none of that works, but im guessing its because models are loaded >> > before the action. Now all I ask is if there is a way to load certain >> > models depending on different actions, instead of loading them all. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
