国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

Yii render和renderPartial的區(qū)別

2019-11-15 01:35:07
字體:
供稿:網(wǎng)友
Yii render和renderPartial的區(qū)別

以下由我們在信易網(wǎng)絡(luò)公司開發(fā)項目的時候終結(jié)出的一些經(jīng)驗

在進行頁面輸出渲染的時候。

1.render 輸出父模板的內(nèi)容,將渲染的內(nèi)容,嵌入父模板。|2.renderPartial 則不輸出父模板的內(nèi)容。只對本次渲染的局部內(nèi)容,進行輸出。同時還有個重要的區(qū)別:

render 函數(shù)內(nèi)部默認執(zhí)行PRocessOutput($output)函數(shù), 會將把組件,比如 CTreeView 里面注冊到 CClientScript 里面的需要的腳本進行渲染輸出。

而renderPartial() 默認不自動渲染輸出客戶端腳本,需要進行參數(shù)的指定,才會輸出:renderPartial($view,$data=null,$return=false,$processOutput=false)指定processOutput 為 true 即可。比如要局部輸出 CTreeView ,用renderPartial 進行渲染,如果按照默認processOutput=false 則輸出內(nèi)容,不含有客戶端腳本輸出內(nèi)容則為 正常的 ul 列表。沒有樹形的折疊效果。 主動設(shè)定 processOutput=true 后,CTreeView 所需的,所有客戶端腳本就會被正常輸出在列表的前面。下面介紹下要用到的幾個相關(guān)的函數(shù):render,renderPartial 不再介紹processOutput()

<?phppublicfunction 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; }}

publicfunction 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 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;}

以上在實際操作中還是比較有用的,比如你不想用大組建,可以直接將變量輸?shù)侥0?也可以將多個變量組成數(shù)組輸?shù)侥0胬锩嫒?/p>

本文由專注于成都網(wǎng)站建設(shè)的信易網(wǎng)絡(luò)發(fā)布,更多關(guān)于yii的信息請關(guān)注信易網(wǎng)絡(luò)隨后的發(fā)布,信易網(wǎng)絡(luò)的官網(wǎng)http://www.ir58.com


上一篇:HHVM簡介(譯)

下一篇:CrazySNS has on line

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 从江县| 台湾省| 崇阳县| 东莞市| 海伦市| 三明市| 邳州市| 合山市| 琼海市| 历史| 成都市| 鄂伦春自治旗| 安徽省| 喜德县| 弥勒县| 宁乡县| 裕民县| 大石桥市| 商河县| 凤台县| 洛扎县| 县级市| 林周县| 淳化县| 扎兰屯市| 浮梁县| 内丘县| 巫溪县| 邳州市| 淮滨县| 永宁县| 肃北| 南漳县| 元谋县| 红河县| 淮北市| 巴里| 长岭县| 青川县| 松桃| 廉江市|