Reputation: 179
What is the equivalent of
Yii::app()->controller->renderPartial
in Yii2 ??
Upvotes: 15
Views: 30885
Reputation: 573
In view files, $this
refers to yii\web\View
object so simply call:
$this->render('partials/_profile', ['name'=>'value']);
and it will work.
Or pass and absolute path to renderFile()
to skip the call to findViewfile()
:
$this->renderFile(dirname(_FILE__) . '/partials/_profile.php', ['name'=>'value']);
Upvotes: 15
Reputation: 57
Yii2, differently of Yii1, uses namespaces. So to call the renderPartial() function you'll need before to call the "yii\base\Controller" namespace, then use renderPartial() function.
Upvotes: 0