View中应用布局和缓存内容部分:

   /**
      * Begins recording a block.
      * This method is a shortcut to beginning [[Block]]
      * 数据块开始的标记,该方法是开始[Block]的快捷方式
      * 数据块可以在一个地方指定视图内容在另一个地方显示,通常和布局一起使用
      * @param string $id the block ID.
      * @param boolean $renderInPlace whether to render the block content in place.
      * Defaults to false, meaning the captured block will not be displayed.
      * @return Block the Block widget instance
      */
     public function beginBlock($id, $renderInPlace = false)
     {
         return Block::begin([
             'id' => $id,//数据块唯一标识
             'renderInPlace' => $renderInPlace,//是否显示标记,默认false不显示
             'view' => $this,
         ]);
     }

     /**
      * Ends recording a block.
      * 数据块结束的标记
      */
     public function endBlock()
     {
         Block::end();
     }

     /**
      * Begins the rendering of content that is to be decorated by the specified view.
      * 开始用指定的view渲染内容,该方法用来实现嵌套布局,传入的第一个参数为布局文件的路径
      * This method can be used to implement nested layout. For example, a layout can be embedded
      * in another layout file specified as '@app/views/layouts/base.php' like the following:
      *
      * ```php
      * <?php $this->beginContent('@app/views/layouts/base.php'); ?>
      * //...layout content here...
      * <?php $this->endContent(); ?>
      * ```
      *
      * @param string $viewFile the view file that will be used to decorate the content enclosed by this widget.
      * This can be specified as either the view file path or path alias.
      * @param string $viewFile 布局文件
      * @param array $params the variables (name => value) to be extracted and made available in the decorative view.
      * @param array $params 布局view文件的参数
      * @return ContentDecorator the ContentDecorator widget instance
      * @see ContentDecorator
      */
     public function beginContent($viewFile, $params = [])
     {
         return ContentDecorator::begin([
             'viewFile' => $viewFile,
             'params' => $params,
             'view' => $this,
         ]);
     }

     /**
      * Ends the rendering of content.
      * 结束渲染内容
      */
     public function endContent()
     {
         ContentDecorator::end();
     }

     /**
      * Begins fragment caching.
      * 开始片段缓存
      * This method will display cached content if it is available.
      * 该方法将展示可用的缓存内容,否则将开始缓存内容直到出现[endCache()]方法
      * If not, it will start caching and would expect an [[endCache()]]
      * call to end the cache and save the content into cache.
      * A typical usage of fragment caching is as follows,
      * 使用缓存的典型例子如下:
      * ```php
      * if ($this->beginCache($id)) {
      *     // ...generate content here
      *     $this->endCache();
      * }
      * ```
      *
      * @param string $id a unique ID identifying the fragment to be cached.
      * @param array $properties initial property values for [[FragmentCache]]
      * @return boolean whether you should generate the content for caching.
      * False if the cached version is available.
      */
     public function beginCache($id, $properties = [])
     {
         $properties['id'] = $id;//缓存唯一标识
         $properties['view'] = $this;
         /* @var $cache FragmentCache */
         $cache = FragmentCache::begin($properties);
         if ($cache->getCachedContent() !== false) {//如果从缓存中读取到了缓存的内容,则渲染内容并返回 false,因此将跳过内容生成逻辑,不再进行缓存
             $this->endCache();

             return false;
         } else {
             return true;
         }
     }

     /**
      * Ends fragment caching.
      * 结束片段缓存
      */
     public function endCache()
     {
         FragmentCache::end();
     }

     /**
      * Marks the beginning of a page.
      * 页面开始标记--用于生成页面布局文件
      */
     public function beginPage()
     {
         ob_start();
         ob_implicit_flush(false);

         $this->trigger(self::EVENT_BEGIN_PAGE);
     }

     /**
      * Marks the ending of a page.
      * 页面结束标记--用于生成页面布局文件
      */
     public function endPage()
     {
         $this->trigger(self::EVENT_END_PAGE);
         ob_end_flush();
     }

Yii源码阅读笔记(二十)的更多相关文章

  1. Yii源码阅读笔记(十二)

    Action类,控制器中方法的基类: namespace yii\base; use Yii; /** * Action is the base class for all controller ac ...

  2. Yii源码阅读笔记(十八)

    View中的查找视图文件方法和渲染文件方法 /** * Finds the view file based on the given view name. * 通过view文件名查找view文件 * ...

  3. Yii源码阅读笔记(十五)

    Model类,集中整个应用的数据和业务逻辑——验证 /** * Returns the attribute labels. * 返回属性的标签 * * Attribute labels are mai ...

  4. Yii源码阅读笔记(十六)

    Model类,集中整个应用的数据和业务逻辑—— /** * Generates a user friendly attribute label based on the give attribute ...

  5. Yii源码阅读笔记(十四)

    Model类,集中整个应用的数据和业务逻辑——场景.属性和标签: /** * Returns a list of scenarios and the corresponding active attr ...

  6. Yii源码阅读笔记(十)

    控制器类,所有控制器的基类,用于调用模型和布局,输出到视图 namespace yii\base; use Yii; /** * Controller is the base class for cl ...

  7. Yii源码阅读笔记(十九)

    View中渲染view视图文件的前置和后置方法,以及渲染动态内容的方法: /** * @return string|boolean the view file currently being rend ...

  8. Yii源码阅读笔记(一)

    今天开始阅读yii2的源码,想深入了解一下yii框架的工作原理,同时学习一下优秀的编码规范和风格.在此记录一下阅读中的小心得. 每个框架都有一个入口文件,首先从入口文件开始,yii2的入口文件位于we ...

  9. werkzeug源码阅读笔记(二) 下

    wsgi.py----第二部分 pop_path_info()函数 先测试一下这个函数的作用: >>> from werkzeug.wsgi import pop_path_info ...

  10. werkzeug源码阅读笔记(二) 上

    因为第一部分是关于初始化的部分的,我就没有发布出来~ wsgi.py----第一部分 在分析这个模块之前, 需要了解一下WSGI, 大致了解了之后再继续~ get_current_url()函数 很明 ...

随机推荐

  1. sybase常用SQL语句,工作中积累的

    -------创建sybase设备 语句--------- disk init name="DEV_DB_CLIENT_DAT26", physname="F:\syba ...

  2. Sql server之路 (三)添加本地数据库SDF文件

    12月25日 今天搞了半天 添加本地数据库Sdf文件到项目里.总是出现问题. 安装环境 Vs2008 没有安装的环境 1.Vs2008 sp1 2. 适用于 Windows 桌面的 Microsoft ...

  3. 0x和H都表示十六进制有什么区别吗?

    0x是16进制的前缀,H是16进制的后缀 都是表示十六进制数,意义上没有什么区别,完全相等.至于什么时候用0x,什么时候用H,这取决于你在什么环境下使用,如果在C/C++,必须用0x来表示. 在C语言 ...

  4. Activity启动方式

    Activity启动方式有四种,分别是: standard singleTop singleTask singleInstance 可以根据实际的需求为Activity设置对应的启动模式,从而可以避免 ...

  5. Unrecognized Windows Sockets error: 0: JVM_Bind

    Unrecognized Windows Sockets error: 0: JVM_Bind [转帖]今天很是奇怪,在运行服务器端的时候,经常遇到这个异常: java.net.SocketExcep ...

  6. hdu 5762 Teacher Bo 曼哈顿路径

    Teacher Bo Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tota ...

  7. hdu 5761 Rowe Bo 微分方程

    1010 Rower Bo 首先这个题微分方程强解显然是可以的,但是可以发现如果设参比较巧妙就能得到很方便的做法. 先分解v_1v​1​​, 设船到原点的距离是rr,容易列出方程 \frac{ dr} ...

  8. request操作的几个容易混淆的请求路径

    假定你的web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 则执行下面向行代码后打印出如下结果 ...

  9. MD5算法 简介

    MD5(单向散列算法)的全称是Message-Digest Algorithm 5(信息-摘要算法),经MD2.MD3和MD4发展而来.MD5算法的使用不需要支付任何版权费用. MD5功能 l 输入任 ...

  10. kmp 和boyer-moore

    <html> <head> <meta http-equiv="content-type" content="text/html; char ...