[英]cakephp: want to create a controller without database model
I am developing a cakephp application, I dont need to use any database tables for my home page, but cake asking for a model and database table, How can I solve this issue ? 我正在开发一个cakephp应用程序,我不需要为我的主页使用任何数据库表,但蛋糕要求模型和数据库表,我该如何解决这个问题? ( using cakephp 1.3)
(使用cakephp 1.3)
Thank you 谢谢
Simply set $uses of your controller to false, like so 只需将控制器的$ uses设置为false,就像这样
class MyController extends AppController {
var $uses = false;
}
Or put your view inside app/views/pages/home.ctp 或者将您的视图放在app / views / pages / home.ctp中
I'm not sure what version was being used but for me, on 1.3.6, $uses
is an array. 我不确定使用的是哪个版本,但对于我来说,在1.3.6上,
$uses
是一个数组。
class MyController extends AppController {
var $uses = array();
}
Details can be seen here: 3.5.3.2 $components, $helpers and $uses 详细信息可以在这里看到: 3.5.3.2 $ components,$ helpers和$ uses
For anybody having the same problem in CakePHP 3.0+, this is what works for me: 对于在CakePHP 3.0+中遇到同样问题的人来说,这对我有用:
class MyController extends AppController {
public function initialize() {
parent::initialize();
$this->modelClass = false;
}
}
对于在2.1+中遇到同样问题的人(尽管文档说的是什么),这对我有用:
public $uses = null;
You can find the answer from the CakePHP official documentation at https://book.cakephp.org/1.2/en/The-Manual/Developing-with-CakePHP/Controllers.html : 您可以从CakePHP官方文档中找到答案, 网址为https://book.cakephp.org/1.2/en/The-Manual/Developing-with-CakePHP/Controllers.html :
If you do not wish to use a Model in your controller, set var $uses = array().
如果您不希望在控制器中使用Model,请设置var $ uses = array()。 This will allow you to use a controller without a need for a corresponding Model file.
这将允许您使用控制器而无需相应的模型文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.