[英]Searching tables without model in CakePHP
I have a table for messages (without a controller and model) that users can submit a message to the admin. 我有一个消息表(没有控制器和模型),用户可以向管理员提交消息。 Aside from creating a messages model and then using loadmodel to search it, is there a better way of doing this? 除了创建消息模型然后使用loadmodel进行搜索之外,还有更好的方法吗?
I would just do something like 我会做类似的事情
//AdminsController
$this->loadmodel('Message');
$this->Message->find(....);
While that is easy to do, I feel like creating a messages model isn't necessary if I can set something up in the Admin model to allow me to do so. 虽然这很容易做到,但我觉得如果我可以在Admin模型中设置一些东西来允许我这样做,那么创建一个消息模型是没有必要的。 Is this possible? 这可能吗?
Cake will use an AppModel instance if a model is requested for which there is no model file found. 如果请求的模型没有找到模型文件,Cake 将使用AppModel实例 。 If a model has no associations and follows conventions (plural name, primary key field id
) - then it's not necessary to create a model file at all. 如果模型没有关联并遵循约定 (复数名称,主键字段id
) - 则根本不需要创建模型文件。
As such the example code in the question will "just work". 因此,问题中的示例代码将“正常工作”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.