joel
joel

Reputation: 125

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 ? ( using cakephp 1.3)

Thank you

Upvotes: 10

Views: 15256

Answers (5)

Jaime Montoya
Jaime Montoya

Reputation: 7701

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.

Upvotes: 0

VCD
VCD

Reputation: 949

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;
   }
}

Upvotes: 7

Choma
Choma

Reputation: 708

For anybody having the same problem in 2.1+ (despite what docs says), this is what works for me:

public $uses = null;

Upvotes: 4

riula
riula

Reputation: 181

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

Upvotes: 11

Andreas Wong
Andreas Wong

Reputation: 60526

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

Upvotes: 15

Related Questions