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

首頁 > 編程 > PHP > 正文

Yii中render和renderPartial的區別_php技巧

2020-03-22 18:51:58
字體:
來源:轉載
供稿:網友
以下由我們在信易網絡公司開發項目的時候終結出的一些經驗
在進行頁面輸出渲染的時候。

1.render 輸出父模板的內容,將渲染的內容,嵌入父模板。|
2.renderPartial 則不輸出父模板的內容。只對本次渲染的局部內容,進行輸出。

同時還有個重要的區別:

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

而renderPartial() 默認不自動渲染輸出客戶端腳本,需要進行參數的指定,才會輸出:
renderPartial($view,$data=null,$return=false,$processOutput=false)
指定processOutput 為 true 即可。

比如要局部輸出 CTreeView ,用renderPartial 進行渲染,如果按照默認processOutput=false 則輸出內容,不含有客戶端腳本
輸出內容則為 正常的 ul 列表。沒有樹形的折疊效果。 主動設定 processOutput=true 后,CTreeView 所需的,所有客戶端腳本就會被正常輸出在列表的前面。

下面介紹下要用到的幾個相關的函數:

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;  }}html' target='_blank'>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;}

以上在實際操作中還是比較有用的,比如你不想用大組建,可以直接將變量輸到模板,也可以將多個變量組成數組輸到模版里面去.

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁国市| 长宁区| 诏安县| 康乐县| 绵竹市| 保康县| 交口县| 赤水市| 专栏| 岱山县| 灌南县| 黄龙县| 阿勒泰市| 睢宁县| 桐城市| 通化县| 磴口县| 特克斯县| 无锡市| 阜平县| 察隅县| 萍乡市| 昭觉县| 洪泽县| 汨罗市| 疏勒县| 花垣县| 上饶县| 洪江市| 尉氏县| 百色市| 浦北县| 湾仔区| 罗城| 兰坪| 玉环县| 连城县| 东源县| 长垣县| 南京市| 东港市|