在 CakePHP 中导入控制器或模型更好吗?
在 CakePHP 应用程序中,导入有权访问模型的控制器还是模型本身更好?
In a CakePHP application, is it better to import Controllers that have access to models or the Models themselves?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您永远不应该导入控制器。控制器只是控制数据流/输入输出的“中心”,它们本身不做任何事情。控制器中不应该有任何重要的、独特的逻辑或数据,因此永远不需要导入它们。控制器也不是模型或类似事物的接口。事实上,您应该尽可能地将模型与控制器分离。如果您对该模型感兴趣,请导入该模型。
You should never import controllers. Controllers are simply "hubs" that control the data flow/input-output, they don't do anything by themselves. You shouldn't have any important, unique logic or data in controllers, and hence should never have a need to import them. Controllers are also not the interface to models or anything like that. In fact, you should decouple your models from the controller as much as possible. If you're interested in the model, import the model.
绝对是模型
definitely the models