Php Yii渲染部分参数
我不太理解renderpartial方法中的第三个和第四个参数(return和processOutput)的作用。这是我在Yii的文档中发现的:Php Yii渲染部分参数,php,yii,Php,Yii,我不太理解renderpartial方法中的第三个和第四个参数(return和processOutput)的作用。这是我在Yii的文档中发现的: public string renderPartial(string $view, array $data=NULL, boolean $return=false, boolean $processOutput=false) - $view (string) name of the view to be rendered. See get
public string renderPartial(string $view, array $data=NULL, boolean $return=false, boolean $processOutput=false)
- $view (string) name of the view to be rendered. See getViewFile for details about how the view script is resolved.
- $data (array) data to be extracted into PHP variables and made available to the view script
- $return (boolean) whether the rendering result should be returned instead of being displayed to end users
- $processOutput (boolean) whether the rendering result should be postprocessed using processOutput.
我环顾了一下四周,但似乎无法确切了解此文档想要表达的内容
任何帮助都将不胜感激。返回选项选择代码回显是否已退出。如果
$return=true代码>这意味着您必须自己提取字符串并回显它。基本上,这就是必须写作的区别
<?php $this->renderPartial($view, $data, false); ?>
(在这里找到:)让我们逐一回答
$return paremeter:它定义是否要将呈现页面的输出发送给客户端(请求该页面的客户端)。这就是它的工作原理:
<?php
ob_start();
?>
<html>
<body>
<p>It's like comparing apples to oranges.</p>
</body>
</html>
<?php
$output=ob_get_contents ();
echo "This is will outputted before";
echo $output;
?>
您可以在此处了解有关php中输出控制的更多信息:
$processOutput参数:如果传递参数true,它将调用CController
的processOutput($output)
函数,这里$output
是从您设置的php页面呈现的内容。默认情况下,它不会在renderPartial
中调用。它在CController的render()
和renderText()
方法中被调用。
引用形式为:
对render()生成的输出进行后处理。此方法在render()和renderText()的末尾调用。如果存在已注册的客户端脚本,此方法将在适当的位置将它们插入到输出中。如果有动态内容,也将插入它们。此方法还可以将持久页面状态保存在页面中有状态表单的隐藏字段中
简单地说,您只需控制第4个参数是否调用此函数
希望有帮助:)
if($processOutput)
$output=$this->processOutput($output);
if($return)
return $output;
else
echo $output;
<?php
ob_start();
?>
<html>
<body>
<p>It's like comparing apples to oranges.</p>
</body>
</html>
<?php
$output=ob_get_contents ();
echo "This is will outputted before";
echo $output;
?>
$output=$this->renderPartial('a_view.php',$data,true);
//this line will generate the output
echo $output;