Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii渲染部分参数_Php_Yii - Fatal编程技术网

Php 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

我不太理解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 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”参数,它表示它控制是否将结果返回或显示给最终用户。这两件事(返回给用户和显示给用户)不是完全一样吗 -例如,我试图通过ajax向页面添加内容。服务器回显json编码的renderpartial语句,客户端的javascript使用jquery方法插入该语句。当我将“return”参数设置为false时,整个ajax操作都会工作,并且成功地将内容插入到我指定的位置。但是,当我将“return”参数设置为true时,服务器仅将代码作为文本而不是html进行响应。客户端的javascript随后会抱怨几个错误……这对我来说毫无意义

  • 什么是后处理?在哪里指定?我知道我没有编写任何“后处理”代码,那么这是从哪里来的呢

  • 任何帮助都将不胜感激。

    返回选项选择代码回显是否已退出。如果
    $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;