D
D
del9937882017-02-07 21:36:02
Yii
del993788, 2017-02-07 21:36:02

How to include php file in views in yii2?

Hello. My index.php, which is in views, is already very crowded due to a lot of if and else. Tell me how in yii2 you can divide the view file into several files, that is: in index.php from views / model / make several include, and in these inserted files already prescribe the conditions? The problem is that I don't know how to link to the file I want to include. I created it and it's located at views/model/ . By default, in yii2 all links lead to the web folder. How to get into views?
PS Will the variable with the array that I pass from the controller propagate to the embedded file?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaliy Orlov, 2017-02-07
@orlov0562

View has a render method , i.e. you can do it right in your view:

$this->render('@app/views/site/index', [
    'var' => 'val',
]);

A
Andrey, 2017-02-07
@reaferon

include(Yii::getAlias('@app/views/part.php'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question