Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Multiple layout in CakePHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 331
    Comment on it

    This blog is going to explain "How to apply multiple layout in CakePHP".
    By default layout file located in (app/View/Layouts/default.ctp) in CakePHP. if we don't apply any layout, then all pages will take default layout.
    if we are required to add multiple layouts for different pages then we can do this as,

    1. Go to /app/views/layouts/ & create firstlayout.ctp
    2. Go to /app/views/layouts/ & create secondlayout.ctp
    Here, firstlayout.ctp & secondlayout.ctp are new file in layout folder where you will add html & CSS code so that pages get new look & feel.

    Change the default layout in all web pages

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

    Different layout in index, view & display for e.g.

        function index() {
          $this->layout='firstlayout';          path: /app/views/layouts/firstlayout.ctp
        }
        function view() {
            $this->layout = 'secondlayout';     path: /app/views/layouts/secondlayout.cpt
        }
        function display() {
            // display page will take mylayout.
        }

    Note: If we don’t want any layout for any action, then we can use controller property $layout = null.

         class UserController extends AppController {
            public $layout = null; // For all actions
            public function index(){
               $this->layout = null; // 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: