The following are some of the experiences we gained when developing projects at Xinyi Network Company
When rendering page output.
1.render outputs the content of the parent template and embeds the rendered content into the parent template. |
2.renderPartial does not output the content of the parent template. Only the partial content of this rendering is output.
At the same time, there is an important difference:
render function, which will render and output the script required by
registered in the component, such as CTreeView, in CClientScript.
And renderPartial() does not automatically render and output client scripts by default. Parameters need to be specified before output:
renderPartial($view,$data=null,$return=false,$processOutput=false)
Set processOutput to true.
For example, if you want to partially output CTreeView, use renderPartial for rendering. If the default processOutput=false is followed, the content will be output. If there is no client script
the output content will be a normal ul list. There is no tree-shaped folding effect. After actively setting processOutput=true, all client scripts required by CTreeView will be output normally at the front of the list.
The following introduces several related functions to be used:
render, renderPartial will not be introduced any more
processOutput()
php
publicfunction render( $view,$data=null,$return=false)
{
if($this->beforeRender($view))
{
$output=$this-> ;renderPartial($view,$data,true);
if(($layoutFile=$this->getLayoutFile($this-> layout))!==false)
$this->renderFile($layoutFile,array ('content'=>$output),true);
$this
->afterRender($view,$output); $output
=$this->processOutput($output);
if($return) publicfunction renderPartial($view,$data=null,$return=false,$processOutput=false) publicfunction processOutput($output) // if using page caching, we should delay dynamic output replacement if($this->_pageStates===null) return $output; 以上在实际操作中还是比较有用的,比如你不想用大组建,可以直接将变量输到模板,也可以将多个变量组成数组输到模版里面去 本文由专注于成都网站建设的信易网络发布,更多关于yii的信息请关注信易网络随后的发布,信易网络的官网http://www.ir58.com
return $output; ;
}
}
{
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
thrownewCException(Yii::t('yii','{controller} cannot find the requested view "{view}".',
array('{controller}'=>get_class($this),'{view}'=>$view)));
}
{
Yii::app()->getClientScript()->render($output);
if($this->_dynamicOutput!==null&& $this->isCachingStackEmpty())
{
$output=$this->processDynamicOutput($output);
$this->_dynamicOutput=null;
}
$this->_pageStates=$this->loadPageStates();
if(!empty($this->_pageStates))
$this->savePageStates($this->_pageStates,$output);
}