CakePHP page title FAQ: I'm still a CakePHP newbie, but I just figured out how to change the page title on my CakePHP view pages (i.e., the HTML TITLE tag on my view pages), so I thought I'd share that process here.
Setting the CakePHP page title
The first step in setting a CakePHP view title is to set the pageTitle
variable in your CakePHP controller method. Here's an example where I set the page title in a typical CakePHP controller index
method:
function index() { // set the cakephp page title here $this->pageTitle = 'A list of all orders'; // do the normal cakephp index page things here $this->Order->recursive = 0; $this->set('ideas', $this->paginate()); }
Setting the title like that isn't enough though. You also have to add one line of code to your layout. In your CakePHP layout page (mine is currently "views/layouts/default.ctp") just add the following variable in between the standard HTML TITLE tags:
<head> <title><? echo $title_for_layout ?></title> <!-- more code here ... --> </head>
Once you've configured your CakePHP layout page like this, you can now control the page title from any of your CakePHP controller functions, which is very nice.
For more information on the CakePHP pageTitle parameter, visit the CakePHP Cookbook page attributes page.