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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 941
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss apply layout in CakePHP.

    Layouts is a very important feature in a CakePHP web application, by default layout in (app/View/Layouts/default.ctp) file. But we can apply different layout in pages as per our requirement.

    By default layout location is:

    app/View/Layouts/default.ctp

     

    When setting a layout in our CakePHP application, we have to follow below cases:


    Case- 1- If we don’t need any layout for our controller method, then we have to set the layout property Null.

    we can see below example:

    <?php 
        class UsersController extends AppController {
          Var $layout = Null; // For all actions
          public function index(){
          $this->layout = Null; // For particular action
          }
        }
    
    
    ?>

     

    Case- 2- If we want to apply any layout in our pages, then we have to set a different layout in our action.
     we can see below example:

    <?php 
        function index(){
           $this->layout='indexlayout'; //app/views/layouts/indexlayout.ctp
        }
        function view(){
          $this->layout = 'viewlayout'; //app/views/layouts/viewlayout.cpt
        }
    
    ?>

    I hope this blog will help you to apply layout in your CakePHP application.

 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: