cakephpcakephp-1.3cakephp-model

Load model or $uses array which need to be used ? while we accessing other models


I have a users controllers, I need to use photos model on that users_controllers which can i use to access that model from the following and which is standard to use?

$this->loadModel('Photo');

or

var $uses =array('User','Photo');

Load model or $uses array which need to be used ?


Solution

  • Like Anh said, it's best to access the model through relations: $this->User->Photo->whatever(). If the models aren't related, use $uses or loadModel().

    The models in $uses are loaded every time the controller is used so it's best to use it only when the other model is needed throughout the controller. If you only need it randomly then loadModel() is better.