Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set - unset layout in CakePHP ?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 112
    Comment on it

    How to set/unset layout in CakePHP ?

    CakePHP provides by default layout in (app/View/Layouts/default.ctp) file, so we need different layouts for different pages as per our requirement.

    Change the default layout in all web pages

    var $layout = 'mylayout'; //This will apply to our all pages.
    

    we can apply a different layout in our Controller methods or action.. for e.g.

    function index() {
    
      $this->layout='layout1';         //app/views/layouts/layout1.ctp
    
    }
    
    function view() {
    
        $this->layout = 'layout2';     //app/views/layouts/layout2.cpt
    
    }
    
    function display() {
    
        // display action will take mylayout.
    
    }
    

    If we dont want any layout for a controller or any action, then we can use controller property $layout.

     class UserController extends AppController {
    
        public $layout = false; // For all actions
    
        public function index(){
           $this->layout = false; // For particular action 
        }
    }
    

 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: