加载模型或 $uses 数组需要使用哪些?当我们访问其他模型时

发布于 2024-11-28 06:49:31 字数 227 浏览 2 评论 0原文

我有一个用户控制器,我需要在该 users_controllers 上使用照片模型 我可以使用哪个来访问以下模型,哪个是使用标准?

$this->loadModel('Photo');

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

加载需要使用的模型或 $uses 数组?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

御守 2024-12-05 06:49:31

就像 Anh 所说,最好通过关系访问模型:$this->User->Photo->whatever()。如果模型不相关,请使用 $usesloadModel()

每次使用控制器时都会加载 $uses 中的模型,因此最好仅在整个控制器需要其他模型时才使用它。如果您只是随机需要它,那么 loadModel() 更好。

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.

虐人心 2024-12-05 06:49:31

标准是让 PhotoUser 模型相互关联(直接或间接):可能是

Photo belongsTo Album belongsTo User.

loadModeluses : 就用你觉得更方便的那个吧。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文