How to have multiple layouts for cakephp?
I am quite confused on how to have my own layout for each page in cakephp. Currently, there is a default.ctp which I have modified to have my main layout and included the $content_for_layout code. So whatever I have entered in the pages\home.ctp gets reflected. But I want to have a login and register layout and also their individual pages. How can I go about ac开发者_开发技巧hieving this? Should I even edit the default.ctp? Or create another layout for my main page?
Please assist.
You can specify a different layout in your Controller methods, e.g.
function index() {
$this->layout='my_index_layout'; //app/views/layouts/my_index_layout.ctp
}
function view($id) {
$this->layout = 'my_view_layout'; //app/views/layouts/my_view/layout.cpt
}
But I want to have a login and register layout and also their individual pages.
The "layout", as understood in Cake, is mostly the header and footer. And it sounds like you are referring to the layout of content. You can do the layout of content in each individual view file.
Should I even edit the default.ctp? Or create another layout for my main page?
Yes, it is there for you to modify. If you want more layouts, you can create more in that folder and specify the layout in the controller (otherwise, it defaults to "default" layout).
精彩评论