Yii视图renderpartial不能渲染css的问题
今天在做页面的时候用到了renderpartial,结果渲染出来的页面非常“骨感”--没有任何CSS的效果。
一开始以为是自己没有把CSS的路径写对,结果仔细查了一番,路径并没有问题,同时结果页面当中也没有包含任何CSS和js脚本。怪哉怪哉!
之前用render是没有问题的,引入的css也是没有问题的,那么问题一定在renderpartial这货身上。
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; } }
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))); }看源码最能解决问题。
render当中实际上也是调用了renderpartial的,唯一不同的就是render当中总是会调用processOutput,而在renderpartial当中则不然。本来指望在processOutput的源码当中看出点儿端倪,结果看了一下完全不知所云。不过问题还是可以解决的,我们看到renderpartial默认的processOutput这个参数为false,我们传一个true进去,ok问题解决。
processOutput=false(默认)时:
processOutput=true时:
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: ThinkPHP3.2.3初学总结
- 下一篇: Yii中render和renderPartial的区别