Set page title in CakePHP

I just noticed that several people are searching for a phrases like "cakephp home change page title" or "page title cakephp" and landing up here. I am sure they must be returning disappointed - so this is an quick tip for them

To set a page title in CakePHP in your controller write

PHP:
  1. $this->set('title', 'My Page Title');

or the less preferred and probably soon to be deprecated

PHP:
  1. $this->pageTitle = 'My Page Title'

However if you are using the pages controller to render a few static pages and want custom title, in your view (static page) use

PHP:
  1. $this->pageTitle = 'My page title';

Hope that helped


About this entry