• missing xbfish.com image

Tag Archives: CakePHP controller model

Controller without Model in CakePHP

Sometimes, we may have a controller that doesn’t required a model in CakePHP. However if there is no Model with a singular name correspond to the controller, CakePHP will return a error of no Model being found.

To resolve this, define the controller variable of uses:

var $uses = null; //declare that this controller has no model

In this way, the error will not be shown because we have specify that the controller does not have any model.

An overview example are as follow:

1
2
3
4
5
6
7
8
9
10
11
12
<?php
class CompaniesController extends AppController {
   var $name = 'Companies';
   var $uses = null; //declare that this controller has no model
   var $layout = 'default';
   var $helpers = array('Html', 'Javascript', 'Time', 'Ajax');
 
   function about_us() {
      $this->pageTitle = "About Us";//will load the view, about_us.ctp
   }
}
?>

Hope this helps!