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)