F
F
Flaker2014-07-03 12:24:05
Yii
Flaker, 2014-07-03 12:24:05

(Yii2) How to include View file?

How to include View files?
If you call the render function, then the variables are not saved.

// В данном случае $model не будет доступна для right_block.
<?php $this->render('blocks/right_block'); ?>

Is there any method for this?
PS With the Include function , it's probably possible, but is there a method offered by the Yii2 framework for this?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2014-07-03
@Flaker

Can't you just pass it on?
<?php $this->render('blocks/right_block',['models' => $models]); ?>

C
Carlos Rodriguez, 2015-01-06
@asf

Rendering in controllers https://github.com/yiisoft/yii2/blob/master/docs/g...
Rendering in widgets https://github.com/yiisoft/yii2/blob/master/docs/g...
Rendering in views https://github.com/yiisoft/yii2/blob/master/docs/g...
Rendering elsewhere https://github.com/yiisoft/yii2/blob/master/docs/g.. .

A
Alexander Gubarev, 2014-07-03
@AlexGx

I'll just leave it here Yii2 Guide: View

L
LAV45, 2014-07-03
@LAV45

<?php include __DIR__ . '/blocks/right_block.php'; ?>

In my opinion, no one has deleted this option yet;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question