Changine title does not work?

$this->pageTitle = ‘xxx’;

in a view or controller does not change the html in between the title tags… only change the H1 tags like:

<h1><?php echo CHtml::encode($model->title); ?></h1>

How to modify the title in <title> </title> tags… I think as most posts I found in this forum suggest using only:

$this->pageTitle

Ah I see calling

$this->setPageTitle(‘test’);

Does change the title tag? is this expected behaviour? Why I cannot find any documentation about it :(

You can see in the file protected/view/layout/main.php that the page title is set like that:


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

In a view, the object this is the controller that calls the render.

So, for set the title you have to do:


 $this->pageTitle="Your favourite Title"; 

This code can be placed whereever the object $this is the controller, so can be in the controller itself or in a view (like the view Contact Us of the default application).

Documentation about setPageTitle can be found by searching "setPageTitle" in the whole site, it find the documentation page of CController in wich this property is defined.

In general, all html you have to modify is generated in view files, so a stuff like


<title></title>

can be or in your view or in the layout view.

I’ve got this problem. Not a big deal, since it does display the app title and the controller name, but not perfect either.

The "<title><?php echo CHtml::encode($this->pageTitle); ?></title>" line is in my protected/view/layout/main.php file. I can put "$this->pageTitle="Your favourite Title";" in any view or controller, and it does nothing.

Any ideas how to fix this?

Dear Friend

It is working. But $this should refer to the current controller.

else you can do the following in your views.




Yii::app()->getController()->pageTitle="Your Favourite Title";