我不太明白第三个和第四个参数(返回和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 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.我环顾四周,但似乎无法理解这些文档到底想说些什么。
-for示例,我试图通过ajax向页面添加内容。服务器回显一个json编码的render分部语句,客户端的javascript通过使用jquery方法插入它。当我将“返回”参数设置为false时,整个ajax操作可以工作,并且成功地将其插入到我指定的位置。但是,当我将“返回”参数设置为true时,服务器只将代码回显为text,而不是html。然后,客户端的javascript抱怨了几个errors...This,对我来说一点意义都没有。
任何帮助都将不胜感激。
发布于 2013-11-11 21:27:08
返回选项选择wheather或不选择代码回显是否已退出。如果是$return = true;,这意味着您必须自己取出字符串并回显它。基本上,这是两种不同的方式
<?php $this->renderPartial($view, $data, false); ?>和
<?php echo $this->renderPartial($view, $data, true); ?>至于$processOutput变量,它用于在html返回之前在html上调用$this->processOutput。这可以用于在ajax请求上生成黑客解决方案--例如,在这里查看一下:http://www.yiiframework.com/forum/index.php/topic/24927-yii-processoutput-only-for-certain-action/和Yii呈现部分(proccessoutput = true)避免重复的js请求 --最常见的情况是,您不会使用这个特性,您不应该担心它:)
如果有什么更清楚的地方,下面是相关的源代码:
if($processOutput)
$output=$this->processOutput($output);
if($return)
return $output;
else
echo $output;(在此发现:http://www.yiiframework.com/doc/api/1.1/CController#renderPartial-detail)
发布于 2013-11-11 21:39:52
让我们一个一个地回答。
This is will outputted before,正如我们所说的,使用ob_start()来使用输出,而不是将输出发送到浏览器(客户端),用ob_get_contents ()检索输出,并将输出存储在$output中。我们可以使用代码的最后两行来演示这个东西。
如果您传递第三个参数true,它将执行类似的操作。它将使用输出并将其作为字符串返回。这样就可以在字符串中捕获输出。
$ output =$this->renderPartial('a_view.php',$data,true);//这一行将生成输出回波$output;
您可以在php中了解更多关于输出控制的信息:输出缓冲控制。CController的processOutput($output)函数,这里$output是从您设置的php页面呈现的内容。默认情况下,它不会在renderPartial中被调用。它在render()和CController.的renderText()方法中被调用,引用自文档:
后置处理由render()生成的输出。在render()和renderText()结尾处调用此方法。如果有已注册的客户端脚本,此方法将将它们插入到适当位置的输出中。如果有动态内容,也会插入它们。此方法还可以将持久页状态保存在页中有状态窗体的隐藏字段中。简单地说,你只需要控制这个函数是否会被第四个参数调用。
希望有帮助:)
https://stackoverflow.com/questions/19915731
复制相似问题