Yii中render和renderPartial的区别
《:Yii中render和renderPartial的区别》要点: PHP学习以下由我们在信易网络公司开发项目的时候终结出的一些经验 1.render 输出父模板的内容,将渲染的内容,嵌入父模板.| 同时还有个重要的区别: render 函数内部默认执行processOutput($output)函数,会将把组件,比如 CTreeView 里面注册到 CClientScript 里面的 而renderPartial() 默认不自动渲染输出客户端脚本,需要进行参数的指定,才会输出: 比如要局部输出 CTreeView,用renderPartial 进行渲染,如果依照默认processOutput=false 则输出内容,不含有客户端脚本 下面介绍下要用到的几个相关的函数: render,renderPartial 不再介绍 <?php publicfunction render($view,$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; } } publicfunction renderPartial($view,$processOutput=false) { if(($viewFile=$this->getViewFile($view))!==false) { $output=$this->renderFile($viewFile,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))); } publicfunction processOutput($output) { Yii::app()->getClientScript()->render($output); // if using page caching,we should delay dynamic output replacement if($this->_dynamicOutput!==null&& $this->isCachingStackEmpty()) { $output=$this->processDynamicOutput($output); $this->_dynamicOutput=null; } if($this->_pageStates===null) $this->_pageStates=$this->loadPageStates(); if(!empty($this->_pageStates)) $this->savePageStates($this->_pageStates,$output); return $output; } 以上在实际操作中还是比拟有用的,比如你不想用大组建,可以直接将变量输到模板,也可以将多个变量组成数组输到模版里面去. 欢迎参与《:Yii中render和renderPartial的区别》讨论,分享您的想法,编程之家 52php.cn为您提供专业教程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |