You can operate on a small number of variables in the Controller to maximize the use of the additional functions of the Controller variable Cake.
You can operate on a small number of variables in the Controller so that you can use the additional functions of Cake to the maximum extent:
$ Name
PHP4 did not name the current camper format class to us. If you have any questions, you can use this variable to set the class name in the correct camper format.
$ Uses
Does your Controller use multiple models? FragglesController automatically loads $ this-> Fraggle, but if you want to access $ this-> Smurf, add the following to your controller:
Var $ uses = array ('fraggl', 'Smurf '); |
Please note how you include the Fraggle model in the $ use array, although it was automatically available before.
$ Helpers
This variable allows the controller to load helper into its view. HTML helper is automatically loaded, but you can use this variable to specify other:
Var $ helpers = array ('html', 'Ajax ', 'javascript '); |
Remember, if you want to use it, you need to include HtmlHelper in the $ helpers array. Generally, it is available by default, but if you define $ helpers without it, you will get an error message in your view.
$ Layout
Set this variable to the layout name you want to use in the controller.
$ AutoRender
Setting this variable to false will automatically stop the render of the action.
$ BeforeFilter
If you want your code to run in every action call (before any action is executed), use $ beforeFilter. this is really good for access control-you can check the user's permissions before any action occurs. Set this variable to an array containing controller actions. Run the following command:
Class ProductsController extends AppController { Var $ beforeFilter = array ('checkaccess '); Function checkAccess () { // Logic to check user identity and access wocould go here .... } Function index () { // When this action is called, checkAccess () is called first. } } |
$ Components
Like $ helpers and $ uses. This variable is used to load components you need:
Var $ components = array ('acl '); [2] |