yiilite.php,YII Framework学习教程-YII的V-view的render若干函数-2011-11-17 | 学步园
YII中,在action可以通過$this->render來指定它的view。其實(shí)還其他一$this->render開頭的函數(shù)。
yiilite.php中有這么幾個(gè)函數(shù)。
public function renderText($text,$return=false)
{
if(($layoutFile=$this->getLayoutFile($this->layout))!==false)
$text=$this->renderFile($layoutFile,array('content'=>$text),true);
$text=$this->processOutput($text);
if($return)
return $text;
else
echo $text;
}
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)));
}
public function renderClip($name,$params=array(),$return=false)
{
$text=isset($this->clips[$name]) ? strtr($this->clips[$name], $params) : '';
if($return)
return $text;
else
echo $text;
}
public function renderDynamic($callback)
{
$n=count($this->_dynamicOutput);
echo "";
$params=func_get_args();
array_shift($params);
$this->renderDynamicInternal($callback,$params);
}
public function renderDynamicInternal($callback,$params)
{
$this->recordCachingAction('','renderDynamicInternal',array($callback,$params));
if(is_string($callback) && method_exists($this,$callback))
$callback=array($this,$callback);
$this->_dynamicOutput[]=call_user_func_array($callback,$params);
}
例如讓action只輸出一句話,不應(yīng)用layout。可以用renderText
/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionIndex()
{
//$viewData=array();
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
//$viewData['homeUrl'] = Yii::app()->homeUrl;
//$viewData['var1'] = '這是var1變量的對應(yīng)的值';
//$this->layout='mylayout';
//$this->renderPartial('index',$viewData);
$this->layout=false;
$this->renderText('test',$return=false);
}
看看上面的render原型,可以看到可以調(diào)用一個(gè)回調(diào)函數(shù)。具體功能可以自己代碼試用一下。
更強(qiáng)大的功能,需要自己慢慢發(fā)現(xiàn)。
總結(jié)
以上是生活随笔為你收集整理的yiilite.php,YII Framework学习教程-YII的V-view的render若干函数-2011-11-17 | 学步园的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 函数参数传递机制_Pyth
- 下一篇: mysql数据库的备份和恢复的常用方法_