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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With