• missing xbfish.com image

Controller without Model in CakePHP

missing xbfish.com image

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!

One comment

  • February 12, 2009 - 1:21 am | Permalink

    Cake so guai lan??
    Nvm, i help u eat the cake

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

    Spam protection by WP Captcha-Free