开发者

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

va开发者_C百科r $uses =array('User','Photo');

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


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.


The standard is having Photo and User model relate to each other (directly or indirectly): maybe

Photo belongsTo Album belongsTo User.

loadModel or uses: just use the one that is more convenient to you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜