renderPartial和render with layout false有什么区别?我知道renderPartial不会包含布局.
$ this-> renderPartial()和$ this-> layout = false; $ this-> render();
不多.内部render()使用renderPartial()并在$layoutif集中包装它.
看看来源:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
和
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)));
}
Run Code Online (Sandbox Code Playgroud)
我能看到的三个不同之处是:
render()与$layout = false运行processOutput(); renderPartial()除非你明确地设置它,否则不会.render()电话beforeRender()和afterRender(); renderPartial()才不是.renderPartial()永远不会渲染任何部分$layout; render()将if $layout设置在任何部分视图中.