Controller Variables
Manipulating a small number of variables in the Controller allows you to maximize the use of Cake’s additional features:
$name
PHP4 does not give us the current class name in camel case format. If you have problems, you can use this variable to set the class name in correct camelCase format.
$uses
Does your Controller use multiple models? FragglesController will automatically load $this->Fraggle, but if you also want to access $this->Smurf, try adding the following to your controller:
var $uses = array('Fraggle','Smurf');
Please note how you use the $use array The Fraggle model is included, although it was automatically available before.
$helpers
Using this variable allows the controller to load the helper into its view. The HTML helper will be loaded automatically, but you can specify others using this variable:
var $helpers = array('Html','Ajax','Javascript');
Remember, if you plan to use it, you need to include HtmlHelper in the $helpers array. Usually it is available by default, but if you define $helpers without it, you will get error messages in your views.
$layout
Set this variable to the layout name you want to use in the controller.
$autoRender
Set this variable to false, which will automatically stop the rendering of the action.
$beforeFilter
If you want a little bit of your code to run on every action call (and before any actions run), use $beforeFilter. This thing is really good for access control - you User permissions can be checked before any action occurs. Set this variable to an array containing controller actions. Can be run as follows:
class ProductsController extends AppController { var $beforeFilter = array('checkAccess'); function checkAccess() { //Logic to check user identity and access would go here.... } function index() { //When this action is called, checkAccess() is called first. } }
$components
Same as $helpers and $uses. This variable is used to load the components you need:
var $components = array('acl');<!--[if !supportFootnotes]-->[2]<!--[endif]-->
The above is the content of the controller variable in cakephp. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!