2015-08-25 14:07:23 3383次浏览 1条回答 0 悬赏 11 金钱

刚才看了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;
	}
}

renderFile()方法第一个参数是布局文件,第二个参数是不带布局的视图

public function renderFile($viewFile,$data=null,$return=false)
{
	$widgetCount=count($this->_widgetStack);
	if(($renderer=Yii::app()->getViewRenderer())!==null && $renderer->fileExtension==='.'.CFileHelper::getExtension($viewFile))
		$content=$renderer->renderFile($this,$viewFile,$data,$return);
	else
		$content=$this->renderInternal($viewFile,$data,$return);
	if(count($this->_widgetStack)===$widgetCount)
		return $content;
	else
	{
		$widget=end($this->_widgetStack);
		throw new CException(Yii::t('yii','{controller} contains improperly nested widget tags in its view "{view}". A {widget} widget does not have an endWidget() call.',
			array('{controller}'=>get_class($this), '{view}'=>$viewFile, '{widget}'=>get_class($widget))));
	}
}

然后这里的第一个参数从名字来看是不是视图(不是布局文件吗?)

public function renderInternal($_viewFile_,$_data_=null,$_return_=false)
{
	// we use special variable names here to avoid conflict when extracting data
	if(is_array($_data_))
		extract($_data_,EXTR_PREFIX_SAME,'data');
	else
		$data=$_data_;
	if($_return_)
	{
		ob_start();
		ob_implicit_flush(false);
		require($_viewFile_);
		return ob_get_clean();
	}
	else
		require($_viewFile_);
}
您需要登录后才可以回答。登录 | 立即注册
xyf90314
副总裁

xyf90314

注册时间:2015-03-04
最后登录:2023-03-13
在线时长:95小时23分
  • 粉丝21
  • 金钱5257
  • 威望40
  • 积分6607

热门问题