How to set the Page Title in Yii Framework 1.1.x

H

How Can We Help?

How to set the Page Title in Yii Framework 1.1.x

In your main layout file always have the following code between the title tag in order to display the title

<title><?php echo CHtml::encode($this->pageTitle); ?></title>

Please note that conditional statements can also be use within the title tag to make displaying of the title more dynamic.

You can set the title in your Controller or View files by using something similar like

$this->pageTitle = 'My new page title';

NOTES:

  • In the controller if the Page Title is not set Yii defaults the Page Title to the Controller and Action name
  • The easiest way to set the Page Title is by setting it within your view files ‘Everybody has there own choice of preference
  • The Page Title won’t display if not echoed between the title tag eg.
    View source
    <title><?php echo CHtml::encode($this->pageTitle); ?></title>

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me