Yii源码阅读笔记(二十)
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源码阅读笔记(二十)的更多相关文章
- Yii源码阅读笔记(十二)
Action类,控制器中方法的基类: namespace yii\base; use Yii; /** * Action is the base class for all controller ac ...
- Yii源码阅读笔记(十八)
View中的查找视图文件方法和渲染文件方法 /** * Finds the view file based on the given view name. * 通过view文件名查找view文件 * ...
- Yii源码阅读笔记(十五)
Model类,集中整个应用的数据和业务逻辑——验证 /** * Returns the attribute labels. * 返回属性的标签 * * Attribute labels are mai ...
- Yii源码阅读笔记(十六)
Model类,集中整个应用的数据和业务逻辑—— /** * Generates a user friendly attribute label based on the give attribute ...
- Yii源码阅读笔记(十四)
Model类,集中整个应用的数据和业务逻辑——场景.属性和标签: /** * Returns a list of scenarios and the corresponding active attr ...
- Yii源码阅读笔记(十)
控制器类,所有控制器的基类,用于调用模型和布局,输出到视图 namespace yii\base; use Yii; /** * Controller is the base class for cl ...
- Yii源码阅读笔记(十九)
View中渲染view视图文件的前置和后置方法,以及渲染动态内容的方法: /** * @return string|boolean the view file currently being rend ...
- Yii源码阅读笔记(一)
今天开始阅读yii2的源码,想深入了解一下yii框架的工作原理,同时学习一下优秀的编码规范和风格.在此记录一下阅读中的小心得. 每个框架都有一个入口文件,首先从入口文件开始,yii2的入口文件位于we ...
- werkzeug源码阅读笔记(二) 下
wsgi.py----第二部分 pop_path_info()函数 先测试一下这个函数的作用: >>> from werkzeug.wsgi import pop_path_info ...
- werkzeug源码阅读笔记(二) 上
因为第一部分是关于初始化的部分的,我就没有发布出来~ wsgi.py----第一部分 在分析这个模块之前, 需要了解一下WSGI, 大致了解了之后再继续~ get_current_url()函数 很明 ...
随机推荐
- 面向服务的体系结构(SOA)——(3)关于BPM
什么是BPM 很多情况下企业当中所提供的服务不是由一个分布式业务流程就可以完成的,整个服务的提供需要多个分布式流程有机的组合,于是BPM就应运而生了.要将现有的服务通过配置.编排(关于配置与编排的区别 ...
- 免费电子书:使用VS Online敏捷管理开源项目
今天推荐的是一本由微软出版社发布的免费电子书,涉及的话题是如何在Visual Studio Online中基于敏捷的思想来管理开源项目. 本书的几位作者(自称ALM领域的游侠),给大家分享了在一个敏捷 ...
- android 自定义弹出框AlertDialog ,很炫的哦
于是就小小的模仿了下自己写了这个这样的效果,主要代码如下:dlg = new AlertDialog.Builder(context).create();dlg.show();dlg.getWin ...
- Android 编程下的四大组件之服务(Service)
服务(Service) 是一种在后台运行,没有界面的组件,由其他组件调用开始.Android 中的服务和 Windows 中的服务是类似的东西,它运行于系统中不容易被用户发觉,可以使用它开发如监控之类 ...
- Web安全性测试总结
一.工具扫描 目前web安全扫描器针对 XSS.SQL injection .OPEN redirect .PHP File Include漏洞的检测技术已经比较成熟. 商业软件web安全扫描器:有I ...
- java中异步多线程超时导致的服务异常
在项目中为了提高大并发量时的性能稳定性,经常会使用到线程池来做多线程异步操作,多线程有2种,一种是实现runnable接口,这种没有返回值,一种是实现Callable接口,这种有返回值. 当其中一个线 ...
- jQuery检查某个元素在网页上是否存在
jQuery选择器有比较完善的处理机制,用jQuery获取网页中不存在的元素也不会报错,值得注意的是,利用$('#tt')获取的永远是对象,即使网页上没有此元素.当使用jQuery检查某个元素在网页上 ...
- BZOJ3682 : Phorni
后缀平衡树+线段树. $O(1)$比较大小的标号法真是强大. #include<cstdio> #include<cmath> #define N 300010 #define ...
- 【原】storm源码之理解Storm中Worker、Executor、Task关系
Storm在集群上运行一个Topology时,主要通过以下3个实体来完成Topology的执行工作:1. Worker(进程)2. Executor(线程)3. Task 下图简要描述了这3者之间的关 ...
- 理解cookie的path和domain属性
今天在做验证码时发现一个问题:A.B窗口都打开同一个页面,A先生成一个验证码,B再生成验证码,这时A所生成的验证码被B覆盖掉了.原因是使用了同名的cookie来存储验证码.一时找不到解决方法就参考了W ...