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)