php 相当于 Yii2 中的“Yii::app()->controller->renderPartial”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27781115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:31:38  来源:igfitidea点击:

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

phpyii2

提问by Abhi

What is the equivalent of

相当于什么

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

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

in Yii2 ??

在 Yii2 ??

回答by user1502826

In view files, $thisrefers to yii\web\Viewobject so simply call:

在视图文件中,$this指的是yii\web\View对象所以简单地调用:

$this->render('partials/_profile', ['name'=>'value']);

and it will work.

它会起作用。

Or pass and absolute path to renderFile()to skip the call to findViewfile():

或者通过绝对路径renderFile()来跳过对 的调用findViewfile()

$this->renderFile(dirname(_FILE__) . '/partials/_profile.php', ['name'=>'value']);

回答by Mahmut Ayd?n

in yii2

在 yii2

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

回答by Diogo Alves

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.

Yii2 与 Yii1 不同,它使用命名空间。因此,要调用 renderPartial() 函数,您需要先调用“yii\base\Controller”命名空间,然后使用 renderPartial() 函数。