以下由我们在信易网络公司开发项目的时候终结出的一些经验

在进行页面输出渲染的时候。

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()

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

以上在实际操作中还是比较有用的,比如你不想用大组建,可以直接将变量输到模板,也可以将多个变量组成数组输到模版里面去

本文由专注于成都网站建设的信易网络发布,更多关于yii的信息请关注信易网络随后的发布,信易网络的官网http://www.ir58.com

最新文章

  1. 【知识必备】RxJava+Retrofit二次封装最佳结合体验,打造懒人封装框架~
  2. SharePoint 2010 网站备份还原简单介绍
  3. ESXi 5.5 命令行克隆虚拟机
  4. php大力力 [024节]PHP中的字符串连接操作(2015-08-27)
  5. 查看Linux系统版本信息
  6. PHPUNIT 单元测试
  7. HTML5 获得canvas油漆环境
  8. springMVC+Hibernate配置
  9. Java集合系列[4]----LinkedHashMap源码分析
  10. 使用commons-csv简单读写CSV文件
  11. Windows + Ubuntu 16.04 双系统安装详细教程
  12. Delphi调用java so
  13. Spring事务管理的demo
  14. Java 里如何实现线程间通信
  15. Sender 转换TButtonItem TCategoryButtons
  16. Mogondb笔记
  17. 【RF库Collections测试】Get From List
  18. ASP.Net Web 服务 – 如何使用会话状态
  19. C# 人民币转成大写
  20. PHP 可以获取客户端哪些访问信息

热门文章

  1. NLog使用说明
  2. IOS开发之带格式的文本
  3. C++ Virtual详解
  4. centos nginx install openssl
  5. Cocos2d-x之Touch事件处理机制
  6. [转] 引用 Java自带的线程池ThreadPoolExecutor详细介绍说明和实例应用
  7. yum在线升级
  8. 简单的实现QQ通信功能(四)
  9. 20160330javaweb之session 小练习
  10. Android网络对讲机的实现