Reputation: 21
Ordinarily if I wanted to include some common code on multiple pages I would use something like:
<?php include_once(__DIR__.'/../someFolder/SomeFile.php' ?>
Just wondering what the preferred way to do this is in Yii2? I have looked at Widgets and Partial views but haven't really been able to conclude this is the best way to factorise common code between pages. I can provide more info, just not sure what too.
Came across this: http://www.yiiframework.com/doc-2.0/guide-structure-views.html#rendering-in-widgets is it likely to be where I should be looking?
Upvotes: 1
Views: 1475
Reputation: 755
Actually you can do the following: view->renderpartial
or just view->render
For example you can use this: <?= \Yii::$app->view->render('fileToInclude', ['id' => $somevariables]); ?>
if it is in the same folder for example
Upvotes: 1
Reputation: 21
Seems I have answered my own question.
<?= \Yii::$app->view->renderFile('@app/views/site/fileToInclude.php'); ?>
If someone can add to this, that would be fantastic, but this seems to answer my question.
Upvotes: 1