Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • CakePHP Controller Basic

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 307
    Comment on it

    A Controller in MVC like cakePHP is basically used to manage the logic around a single model.

    LIke for example if you are working on User model than  you have to have a controller for it name UsersController.php for managing the model.

    But it is possible to manage the different model from a single controller too by using $uses variable and defining the model you are going to use in that controller and also by using loadModel().

    Controller actions are responsible for converting the request parameters to response for user.

    CakePHP uses conventions to automate this process and remove some boilerplate code you would otherwise need to write

    Request Life-cycle callbacks

    CakePHP controller have callbacks which can be used to insert the logic.

    1. beforeFilter- This function is executed before any action in the controller.

    It is used for permission and check for an active session.

     

    public function beforeFilter(){
            parent::beforeFilter();
            $this->Auth->allow('about', 'contact','forgetpwd','reset', 'login');
        }

    2. beforeRender()- It is called after controller logic but before the view is rendered. It is mostly not used.

    3. afterFilter()- It is called after every controller action and after the rendering is complete.
     

    public function afterFilter(){
            parent::afterFilter();
            $this->Auth->allow(,'getCity', 'edit','deleteimg','deletecarimg','change'}
    
    

     

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: