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, Ho开发者_StackOverflow中文版w can I solve this issue ? ( using cakephp 1.3)
Thank you
Simply set $uses of your controller to false, like so
class MyController extends AppController {
var $uses = false;
}
Or put your view inside 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.
class MyController extends AppController {
var $uses = array();
}
Details can be seen here: 3.5.3.2 $components, $helpers and $uses
For anybody having the same problem in CakePHP 3.0+, this is what works for me:
class MyController extends AppController {
public function initialize() {
parent::initialize();
$this->modelClass = false;
}
}
For anybody having the same problem in 2.1+ (despite what docs says), this is what works for me:
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:
If you do not wish to use a Model in your controller, set var $uses = array(). This will allow you to use a controller without a need for a corresponding Model file.
精彩评论