php - Yii 2: Can I access a variable in a view that's rendered by another view? -


in yii 2, following mvc pattern controller passes variables view. however, view renders view in itself.

for example in default generated crud views, both create.php , update.php render _form view:

<?= $this->render('_form', [     'model' => $model, ]) ?> 

is possible me use variable passed controller create.php in _form?

say controller renders this:

return $this->render( 'create', [     'model' => $model,     'myvar' => $myvalue, ] ); 

now can access $myvar in create.php can't in _form (which rendered create.php. there anyway can access this? or need explicitly pass form (in create.php):

return $this->render( '_form', [     'model' => $model,     'myvar' => $myvalue, ] ); 

the render-function uses extract() convert parameters regular variables in local function context, include of file done. how "receive" values in view.

this means if call render (or of other variants) again within view, create new local context , local variables "above" won't there. why required pass along variables every call, figured out yourself.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -