Setting Your Page Layout in CakePHP
I am not a pro in CakePHP, and in fact, i am just a beginner who wanted to explore it. When I was on my way to creating my goal, I stumbled upon a problem on how to change and then set the new page layout to be used. Honestly, the problem didn’t took me long to solve. I was lucky to have read the manual on the official site. So to cut the long story short, here is the list of steps which I did to come up with my new and first page layout on my CakePHP inspired website and you might consider following this little manual, too.
1. First, design the layout that you wanted to implement and use. Assuming we have the simple code below as your desired page layout.
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
2. After having established the base, let us now put the code that will show the title of your page. We will use $title_for_layout to do the job. So your head section will now look like this:
<head>
<title><?php echo $title_for_layout?></title>
</head>
3. Next inline would be displaying the contents. We will use $content_for_layout. It will tell CakePHP where to place the code for your views. Our code now will look like this one.
<html>
<head>
<title><?php echo $title_for_layout?></title>
</head>
<body>
<?php echo $content_for_layout ?>
</body>
</html>
4. Then save it as app/views/layouts/default.ctp.
Next topic would be creating and using multitle layouts for single website. Please feel free to share your views which you think can help us beginners make a step higher on CakePHP.

July 21st, 2008 at 7:24 am
where do you save the definitions variables ($title_for_layout)?
July 21st, 2008 at 8:07 pm
Hi ajk,
About your question, $title_for_layout will get the filename of your views files minus the “.ctp” and will use it as your title. This is true if your views files are located inside app/views/pages folder. But if you have created your own folder inside views, say app/views/registers, the name of the folder will now be the page title for all views files inside app/views/registers.
However, if you wish to customize your title, you can do that using $pageTitle controller variable. You will put it on your controller file. To show what I mean, here’s a sample code:
class RegistersController extends AppController {
var $name = ‘Registers’;
function index() {
$this->pageTitle = ‘Manage Admin Panel’;
$this->checkSession();
}
So now, if you will open the page say url/registers/index on your browser, the tilte bar will show ‘Manage Admin Panel’.
Thanks,
Cyrose
August 4th, 2008 at 2:50 am
To ajk, I think the title can be set in your controller by the following;
$this->set(’title’, ‘your page title’);