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)