Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我计划在整个站点的视图文件中显示图像,所以我可以导入模型并将查询写入 app_helper 文件吗???
在 app_helper 中特别是在 cakephp 中编写查找查询是一种很好的格式吗?
谢谢
您可以像这样在任何地方导入模型:
App::import('Model','MyModel'); $MyModel = new MyModel();
然而,直接访问助手中的模型违反了所有 CakePHP 约定。如果您想在站点的任何地方使用它,编写一个组件来执行模型导入和查询以及一个帮助器来显示结果并将组件和帮助器包含在您的 AppController 中会更像 Cake。