View.php,继承了component,用于渲染视图文件:

 namespace yii\base;

 use Yii;
 use yii\helpers\FileHelper;
 use yii\widgets\Block;
 use yii\widgets\ContentDecorator;
 use yii\widgets\FragmentCache;

 /**
  * View represents a view object in the MVC pattern.
  *
  * View provides a set of methods (e.g. [[render()]]) for rendering purpose.
  * 视图提供了一套渲染页面的方法(例如[render()])
  *
  * @property string|boolean $viewFile The view file currently being rendered. False if no view file is being
  * rendered. This property is read-only.
  *
  * @author Qiang Xue <qiang.xue@gmail.com>
  * @since 2.0
  */
 class View extends Component
 {
     /**
      * @event Event an event that is triggered by [[beginPage()]].
      * beginPage事件名常量,被[beginPage()]触发
      */
     const EVENT_BEGIN_PAGE = 'beginPage';
     /**
      * @event Event an event that is triggered by [[endPage()]].
      * endPage事件名常量,被[endPage()]触发
      */
     const EVENT_END_PAGE = 'endPage';
     /**
      * @event ViewEvent an event that is triggered by [[renderFile()]] right before it renders a view file.
      * beforeRender事件名常量,被[renderFile()]触发
      */
     const EVENT_BEFORE_RENDER = 'beforeRender';
     /**
      * @event ViewEvent an event that is triggered by [[renderFile()]] right after it renders a view file.
      * afterRender事件名常量,被[renderFile()]触发
      */
     const EVENT_AFTER_RENDER = 'afterRender';

     /**
      * @var ViewContextInterface the context under which the [[renderFile()]] method is being invoked.
      */
     public $context;
     /**
      * @var mixed custom parameters that are shared among view templates.
      * 在视图模板中共享的自定义参数
      */
     public $params = [];
     /**
      * @var array a list of available renderers indexed by their corresponding supported file extensions.
      * Each renderer may be a view renderer object or the configuration for creating the renderer object.
      * 一个可用的渲染索引列表。每个渲染器是一个渲染器对象或创建渲染对象配置数组
      * For example, the following configuration enables both Smarty and Twig view renderers:
      * 下面的配置数组同时支持 Smarty 和 Twig
      *
      * ```php
      * [
      *     'tpl' => ['class' => 'yii\smarty\ViewRenderer'],
      *     'twig' => ['class' => 'yii\twig\ViewRenderer'],
      * ]
      * ```
      *
      * If no renderer is available for the given view file, the view file will be treated as a normal PHP
      * and rendered via [[renderPhpFile()]].
      * 如果没有值,则
      */
     public $renderers;
     /**
      * @var string the default view file extension. This will be appended to view file names if they don't have file extensions.
      * 默认视图文件扩展名,在视图文件没有扩展名的情况下自动添加
      */
     public $defaultExtension = 'php';
     /**
      * @var Theme|array|string the theme object or the configuration for creating the theme object.
      * If not set, it means theming is not enabled.
      * 主题对象或创建主题对象的配置
      */
     public $theme;
     /**
      * @var array a list of named output blocks. The keys are the block names and the values
      * are the corresponding block content. You can call [[beginBlock()]] and [[endBlock()]]
      * to capture small fragments of a view. They can be later accessed somewhere else
      * through this property.
      * 一个输出块列表。键是块名称值为相应的块内容。你可以调用 [ beginblock() ]和[ endblock() ]捕获视图的small fragments
      * 它们可以在其他地方通过这个属性访问。
      */
     public $blocks;
     /**
      * @var array a list of currently active fragment cache widgets. This property
      * is used internally to implement the content caching feature. Do not modify it directly.
      * 当前active fragment缓存小部件的列表。此属性用于内部实现内容缓存功能。不要直接修改它。
      * @internal
      */
     public $cacheStack = [];
     /**
      * @var array a list of placeholders for embedding dynamic contents. This property
      * is used internally to implement the content caching feature. Do not modify it directly.
      * 一种嵌入动态内容占位符列表。此属性用于内部实现内容缓存功能。不要直接修改它。
      * @internal
      */
     public $dynamicPlaceholders = [];

     /**
      * @var array the view files currently being rendered. There may be multiple view files being
      * rendered at a moment because one view may be rendered within another.
      * 目前正在渲染的视图文件。可能有多个视图文件被渲染,因为一个视图可以在另一个视图中呈现
      */
     private $_viewFiles = [];

     /**
      * Initializes the view component.
      * 初始化视图组件
      */
     public function init()
     {
         parent::init();//调用父类的init方法
         if (is_array($this->theme)) {//如果theme是数组
             if (!isset($this->theme['class'])) {//且没有设置类名
                 $this->theme['class'] = 'yii\base\Theme';//则类名为'yii\base\Theme'
             }
             //以配置的形式创建对象
             $this->theme = Yii::createObject($this->theme);
         } elseif (is_string($this->theme)) {//否则以字符串参数的形式创建
             $this->theme = Yii::createObject($this->theme);
         }
     }

     /**
      * Renders a view.
      * 渲染一个视图
      * The view to be rendered can be specified in one of the following formats:
      * 被渲染的视图可以用下列方式指定
      *
      * - path alias (e.g. "@app/views/site/index");
      *   路径别名
      * - absolute path within application (e.g. "//site/index"): the view name starts with double slashes.
      *   The actual view file will be looked for under the [[Application::viewPath|view path]] of the application.
      *   绝对路径,将会在[Application::viewPath|view path]下查找文件
      * - absolute path within current module (e.g. "/site/index"): the view name starts with a single slash.
      *   The actual view file will be looked for under the [[Module::viewPath|view path]] of the [[Controller::module|current module]].
      *   模块下的绝对路径,将会在[Module::viewPath|view path]下查找文件
      * - relative view (e.g. "index"): the view name does not start with `@` or `/`. The corresponding view file will be
      *   looked for under the [[ViewContextInterface::getViewPath()|view path]] of the view `$context`.
      *   相对路径,将会在[ViewContextInterface::getViewPath()|view path]下查找文件
      *   If `$context` is not given, it will be looked for under the directory containing the view currently
      *   being rendered (i.e., this happens when rendering a view within another view).
      *
      * @param string $view the view name.
      * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
      * @param object $context the context to be assigned to the view and can later be accessed via [[context]]
      * in the view. If the context implements [[ViewContextInterface]], it may also be used to locate
      * the view file corresponding to a relative view name.
      * @return string the rendering result
      * @throws InvalidParamException if the view cannot be resolved or the view file does not exist.
      * @see renderFile()
      */
     public function render($view, $params = [], $context = null)
     {
         //查找视图文件路径
         $viewFile = $this->findViewFile($view, $context);
         //调用renderFile()渲染视图文件
         return $this->renderFile($viewFile, $params, $context);
     }

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

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

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

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

    Theme 类,即一个应用的主题,主要通过替换路径实现主题的应用,里边的方法为获取根路径和根链接,以及应用主题的方法: namespace yii\base; use Yii; use yii\hel ...

  3. Yii源码阅读笔记(八)

    前面阅读了Yii2的两个基本类Object和Component,了解了Yii的三个重要概念属性.事件.行为,下面开始阅读Event类,Event类是所有事件类的基类: <?php /** * @ ...

  4. Yii源码阅读笔记(三)

    接着上次的继续阅读BaseYii.php vendor/yiisoft/yii2/BaseYii.php—— public static function getRootAlias($alias)// ...

  5. Yii源码阅读笔记(二)

    接下来阅读BaseYii.php vendor/yiisoft/yii2/BaseYii.php—— namespace yii; use yii\base\InvalidConfigExceptio ...

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

    Container,用于动态地创建.注入依赖单元,映射依赖关系等功能,减少了许多代码量,降低代码耦合程度,提高项目的可维护性. namespace yii\di; use ReflectionClas ...

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

    Instance类, 表示依赖注入容器或服务定位器中对某一个对象的引用 namespace yii\di; use Yii; use yii\base\InvalidConfigException; ...

  8. Yii源码阅读笔记(三十三)

    ServiceLocator,服务定位类,用于yii2中的依赖注入,通过以ID为索引的方式缓存服务或则组件的实例来定位服务或者组件: namespace yii\di; use Yii; use Cl ...

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

    web/Application类的注释,继承base/Application类,针对web应用的一些处理: namespace yii\web; use Yii; use yii\base\Inval ...

随机推荐

  1. errno 错误码

    转自:http://baike.baidu.com/link?url=uX-q7K-TTL-5AFNT-hjhAP6fvgAwvsNkIMqJqJ3GEspYgtQXsovEEzpqmQ3ZmAgql ...

  2. 2016国产开源软件TOP100(Q1)

    随着互联网的发展.开放标准的普及和虚拟化技术的应用等诸多IT新领域的创新及拓展,开源技术凭借其开放性.低成本.稳定性.灵活性.安全性和技术创新性等特点迅速走向成熟,逐步发展成为一种主流模式,日益改变着 ...

  3. .net学习之多线程、线程死锁、线程通信 生产者消费者模式、委托的简单使用、GDI(图形设计接口)常用的方法

    1.多线程简单使用(1)进程是不执行代码的,执行代码的是线程,一个进程默认有一个线程(2)线程默认情况下都是前台线程,要所有的前台线程退出以后程序才会退出,进程里默认的线程我们叫做主线程或者叫做UI线 ...

  4. ThinkPHP3.2判断是否为手机端访问并跳转到另一个模块的方法

    目录结构 公共模块Common,Home模块,Mobile模块 配置Application/Common/Conf/config.php文件 'MODULE_ALLOW_LIST' => 'Ho ...

  5. Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set乱搞

    D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  6. Codeforces Round #Pi (Div. 2) A. Lineland Mail 水

    A. Lineland MailTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/proble ...

  7. pagefile.sys and heberfil.sys

    dub 删除heberfil.sys大文件的方法 方法1:Windows/system32中的cmd.exe  输入 powercfg -h off,即可关闭休眠功能,同时 Hiberfil.sys ...

  8. 【转】Hadoop集群添加磁盘步骤

    转自:http://blog.csdn.net/huyuxiang999/article/details/17691405 一.实验环境 : 1.硬件:3台DELL服务器,CPU:2.27GHz*16 ...

  9. linux根分区扩容

    Linux 根分区扩容 1.fdisk –l  (红线部分为新添加的硬盘) 2.磁盘格式化 3. mkfs.ext3 -T largefile /dev/sde(格式化上面的分区) 4. vgdisp ...

  10. VMware Tools安装

    不是每一个程序员都必须玩过linux,只是博主觉得现在的很多服务器都是linux系统的,而自己属于那种前端也搞,后台也搞,对框架搭建也感兴趣,但是很多生产上的框架和工具都是安装在服务器上的,而且有不少 ...