Abhi
Abhi

Reputation: 179

Equivalent of "Yii::app()->controller->renderPartial" in Yii2?

What is the equivalent of

Yii::app()->controller->renderPartial

in Yii2 ??

Upvotes: 15

Views: 30885

Answers (3)

Mahmut Aydın
Mahmut Aydın

Reputation: 869

in yii2

Yii::$app->controller->renderPartial('myview');

Upvotes: 18

user1502826
user1502826

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

Diogo Alves
Diogo Alves

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

Related Questions