Controller variable in cakephp

Source: Internet
Author: User
Abstract: operating a small number of variables in the Controller allows you to use the additional functions of Cake to the maximum extent...

Controller variable

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('Fraggle','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 would 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');

The above is the content of the controller variable in cakephp. For more information, see The PHP Chinese website ( )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.