yii框架默认会渲染/protected/views/laytout/main.php布局文件,当然我们也可以自己设置控制器特有的布局文件,设置很简单:
<?php class PostController extends Controller { public $layout='column2';
那么有了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; } }