How to set the title
value from the controller ? Yii2
2 answers
As far as I know, in yii2
they refused to set the title in the controller and transferred this action to the view
.
In a view, you can do this: $this->title = "Мой заголовок";
If you really want to set the title in the controller, you will most likely have to define a variable in it to write the value to and transfer it to the view:
$title = 'Мой заголовок'; return $this->render('myPage', ['title' => $title]);
And in view
write:
$this->title = $title;
|
class SiteController extends Controller { public function actionIndex() { $this->getView()->title = 'Мой заголовок'; return $this->render('index'); } }
|
view
does not suit? - Alexey Shimansky$this->title
? - Andrey Kolomensky