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
Equivalent of "Yii::app()->controller->renderPartial" in Yii2?
提问by Abhi
What is the equivalent of
相当于什么
Yii::app()->controller->renderPartial
Yii::app()->controller->renderPartial
in Yii2 ??
在 Yii2 ??
回答by user1502826
In view files, $this
refers to yii\web\View
object 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() 函数。