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)));
}
我能看到的三个区别是:
render()
与$layout = false
将运行processOutput()
;除非您明确设置renderPartial()
,否则它不会- CCD_ 12调用CCD_ 13和CCD_;
renderPartial()
没有 - 在具有多个局部视图的场景中,
renderPartial()
将永远不会渲染任何$layout
;如果在任何局部视图中设置了CCD_ 19,则CCD_