What performance differences do you see? Let's say ModelA has references to
ModelB, ModelC, ModelD...

You use only ModelA on your controller but access B, C, and D through its
linkage with A.

When CakePHP takes the var $uses array it will instantiate all models in
there, and for each model it will *instantiate* all models linked to it. You
can see this when the Model constructor calls:

$this->__createLinks();

That has:

foreach($this->__associations as $type) {
        $this->__constructLinkedModel($assoc, $className);
}

And __constructLinkedModel() has:

if(!class_exists($className)){
        loadModel($className);
}

if (ClassRegistry::isKeySet($colKey)) {
        $this->{$assoc} = ClassRegistry::getObject($colKey);
        $this->{$className} = $this->{$assoc};
} else {
        $this->{$assoc} = new $className();
        $this->{$className} = $this->{$assoc};
}

On the other hand Controller::constructClasses() has:

foreach($uses as $modelClass) {
        if(!class_exists($modelClass)){
                loadModel($modelClass);
        } 

        $model =& new $modelClass($id);
        $this->{$modelClass} =& $model;
}

So what is the big boost in performance you see when you choose one method
over the other?

And BTW, Code Readability (and as such Maintenance) is, in my opinion, *AS
IMPORTANT* (if not more) as performance. Hardware is cheaper than
developer's time.

-MI

---------------------------------------------------------------------------

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de CraZyLeGs
Enviado el: Lunes, 26 de Febrero de 2007 07:44 a.m.
Para: Cake PHP
Asunto: Re: Passing value from appController to all models used by an action

If it's there, no need for $uses.
I think performance is much more important than Source code
readability, and hey $this->modelClass->AssocModel isn't that ugly
compared to $this->AssocModel

a rule of thumb would be:
When trying to use a model, first thing to check is, is it linked to a
model I already have. if it's not available, and if I'm going to use
it in quite a few of the actions, put it in uses, if it's just a quick
use, check the Registry if it's not there, loadModel()-it and create
it.

This is true for components too.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to