本文共 764 字,大约阅读时间需要 2 分钟。
yii框架默认会渲染/protected/views/laytout/main.php布局文件,当然我们也可以自己设置控制器特有的布局文件,设置很简单:
设置控制器类的 $layout属性为你想要渲染的布局文件就ok了
那么有了layout布局后,$this->render('index',array('dataProvider'=>$dataProvider,));,yii是先渲染column2布局文件还是先渲染index.php视图模版呢,答案很简单,我们看下
CController.php文件中的render函数就明白了:
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; } }可以看到yii是先通过renderPartial来渲染视图模版,然后把模版渲染的结果放入content变量中通过renderFile去渲染布局文件
转载地址:http://egimb.baihongyu.com/