In Yii 2, following the MVC pattern, the controller passes certain variables to the mind. However, sometimes the view makes a different appearance on its own.
For example, in the CRUD views created by default, both create.php and update.php display the _form view:
<?= $this->render('_form', [
'model' => $model,
]) ?>
Is it possible to use the variable passed by the controller to create.php in _form?
Say the controller does it like this:
return $this->render( 'create', [
'model' => $model,
'myVar' => $myValue,
] );
Now I can access $ myVar in the create.php file, but I cannot in _form (which is rendered using create.php. Is there anyway I can access it? Or do I need to explicitly pass it like this, in create.php file):
return $this->render( '_form', [
'model' => $model,
'myVar' => $myValue,
] );
source
share