动态缓存renderDynamic的不解

在GG搜索renderDynamic的用法时,发现是这样用的:

$this->renderDynamic(‘widget’,'application.extensions.uinfo’,array(‘uid’=>’hahahah!’), true);

我看了API和源代码,CController::renderDynamic里面只有一个参数,$callback

为什么网上流传的方法可以传这些参数呢,标准的做法是什么样呢,希望官方能提供一个标准的做法,谢谢

renderDynamic参数有这样几种形式:

$this->renderDynamic("methodName");//methodName为你当前的Controller中的一个方法名,该方法必须返回内容而不是echo

$this->renderDynamic("globalFunctionName");//renderDynamic方法第一个参数为字符串时,Yii会先查看当前Controller有没有对应方法,如果没有则将其当成全局函数名称

$this->renderDynamic(array($obj,‘objsMethodName’));//事实上这几种参数形式都对应于php中的Callback的形式

如果renderDynamic方法不止传了一个参数,其它的参数则会作为对应的要调用的方法的参数

对于你所提的

$this->renderDynamic(‘widget’,'application.extensions.uinfo’,array(‘uid’=>’hahahah!’), true);

最终调用形式为

$this->widget('application.extensions.uinfo’,array(‘uid’=>’hahahah!’), true);

文档上虽然只列出了第一个参数$callback,但下面也有说明的:

The first parameter to this method should be a valid PHP callback, while the rest parameters will be passed to the callback.

Note, the callback and its parameter values will be serialized and saved in cache. Make sure they are serializable.

PL4CJ Yii Framework Discuss

哦,原来是有note的,非常感谢