$this之间的差异->;renderPartial()和$this->;render()使用$this->


Difference between $this->renderPartial() and $this->render() using $this->layout=false

renderPartial和使用布局false渲染之间有什么区别?我知道renderPartial不会包括布局。

$this->renderPartial()$this->layout=false; $this->render();

不多。render()在内部使用renderPartial(),并将其封装在$layout中(如果设置的话)。

看看来源:

public function render($view,$data=null,$return=false)
{
    if($this->beforeRender($view))
    {
        $output=$this->renderPartial($view,$data,true);
        if(($layoutFile=$this->getLayoutFile($this->layout))!==false)
            $output=$this->renderFile($layoutFile,array('content'=>$output),true);
        $this->afterRender($view,$output);
        $output=$this->processOutput($output);
        if($return)
            return $output;
        else
            echo $output;
    }
}

public function renderPartial($view,$data=null,$return=false,$processOutput=false)
{
    if(($viewFile=$this->getViewFile($view))!==false)
    {
        $output=$this->renderFile($viewFile,$data,true);
        if($processOutput)
            $output=$this->processOutput($output);
        if($return)
            return $output;
        else
            echo $output;
    }
    else
        throw new CException(Yii::t('yii','{controller} cannot find the requested view "{view}".',
            array('{controller}'=>get_class($this), '{view}'=>$view)));
}

我能看到的三个区别是:

  1. render()$layout = false将运行processOutput();除非您明确设置renderPartial(),否则它不会
  2. CCD_ 12调用CCD_ 13和CCD_;renderPartial()没有
  3. 在具有多个局部视图的场景中,renderPartial()将永远不会渲染任何$layout;如果在任何局部视图中设置了CCD_ 19,则CCD_