How to generate dynamic page title in Yii2

Hi,

I just want to know how I can setup different page titles for different Pages. I mean dynamic pagetitle.

Here I found a solution that we can setup it in the view files like :


 $this->title = "your-page-title-here"; 

Can we setup it from our controller as in Yii1.

Any help will be much appreciated.

You can access the View object from controller by $this->view

So, you can do the following:




public function actionIndex()

{

    $this->view->title = 'custom-title';

    return $this->render('index');

}



And remove the following line from view file




$this->title = '...';



Yeah, that works fine

Thanks @Richard Fan