Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii 2 Quicker way to access controller from view

So in Yii 1, in the view file you could access the Controller's properties / actions using $this->action() or $this->property.

In Yii 2, the only way I can see this possible is using Yii::$app->controller->property or Yii::$app->controller->action(). I am one for not wanting to write more code than is necessary, so I was wondering if there's a shorter method of doing it.

like image 981
Stefan Dunn Avatar asked May 28 '15 15:05

Stefan Dunn


1 Answers

For view controller is basically "context" where render of this view was called.

There is special property to get current related controller from view and it's called exactly like this: context.

Example: $this->context

Official docs:

  • View context
like image 190
arogachev Avatar answered Oct 22 '22 22:10

arogachev