Yii源码阅读笔记(二十五)
Module类中剩余部分代码,通过控制器ID实例化当前模块的控制器,当前模块的Action方法的前置和后置方法:
/**
* This method is invoked right before an action within this module is executed.
* 该方法是当前模块的Action执行前调用的方法,将会触发[[EVENT_BEFORE_ACTION]]事件
*
* The method will trigger the [[EVENT_BEFORE_ACTION]] event. The return value of the method
* will determine whether the action should continue to run.
* 如果返回true,Action方法才会执行,否则终止执行
*
* In case the action should not run, the request should be handled inside of the `beforeAction` code
* by either providing the necessary output or redirecting the request. Otherwise the response will be empty.
*
* If you override this method, your code should look like the following:
* 如果要重写该方法,代码格式如下:
*
* ```php
* public function beforeAction($action)
* {
* if (!parent::beforeAction($action)) {//先要判断父类的beforeAction方法执行结果
* return false;
* }
*
* // your custom code here
*
* return true; // or false to not run the action
* }
* ```
*
* @param Action $action the action to be executed.
* @return boolean whether the action should continue to be executed.
*/
public function beforeAction($action)
{
$event = new ActionEvent($action);//实例化ActionEvent()
$this->trigger(self::EVENT_BEFORE_ACTION, $event);//触发beforeAction事件
return $event->isValid;//返回结果
}
/**
* This method is invoked right after an action within this module is executed.
* 该方法是当前模块的Action执行后调用的方法,将会触发[[EVENT_AFTER_ACTION]]事件
* The method will trigger the [[EVENT_AFTER_ACTION]] event. The return value of the method
* will be used as the action return value.
* 如果返回true,后面的代码才会继续执行,否则终止执行
*
* If you override this method, your code should look like the following:
* 如果要重写该方法,代码格式如下:
*
* ```php
* public function afterAction($action, $result)
* {
* $result = parent::afterAction($action, $result);//先要判断父类的afterAction方法执行结果
* // your custom code here
* return $result;
* }
* ```
*
* @param Action $action the action just executed.
* @param mixed $result the action return result.
* @return mixed the processed action result.
*/
public function afterAction($action, $result)
{
$event = new ActionEvent($action);//实例化ActionEvent()
$event->result = $result;//将Action方法的执行结果赋值给result常量
$this->trigger(self::EVENT_AFTER_ACTION, $event);//触发beforeAction事件
return $event->result;//返回结果
}
Yii源码阅读笔记(二十五)的更多相关文章
- Yii源码阅读笔记(十五)
Model类,集中整个应用的数据和业务逻辑——验证 /** * Returns the attribute labels. * 返回属性的标签 * * Attribute labels are mai ...
- 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类,集中整个应用的数据和业务逻辑—— /** * 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 ...
- Spring源码分析(二十五)finishRefresh
摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. 在 Spring 中还提供了 Lifecycle 接口, Lifecy ...
随机推荐
- json解析不推荐使用eval
推荐使用JSON.parse() 低版本浏览器(IE6/7)不支持此方法,可以通过网上下载json2.js,引入到文件中,此文件通过判断浏览器是否支持JSON.parse()方法,如果不支持,文件中编 ...
- 【转】浅谈 C++ 中的 new/delete 和 new[]/delete[]
在 C++ 中,你也许经常使用 new 和 delete 来动态申请和释放内存,但你可曾想过以下问题呢? new 和 delete 是函数吗? new [] 和 delete [] 又是什么?什么时候 ...
- webApi实践:开始WebApi 2
1.学习步骤总结 学习网址:http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-you ...
- 每天一个linux命令--locate
linux下,不知道自己安装的程序放在哪里了,可以使用locate命令进行查找. [hongye@dev107 ~]$ locate activemq.xml /home/hongye/hongyeC ...
- JNDI 配置:JBoss + MySQL
一.JNDI 名词解释 JNDI 是Java 命名和目录接口(Java Naming and Directory Interface,JNDI)的简称.从一开始就一直是 Java 2 平台企业版(JE ...
- praise包--R给你点赞!
1.praise包干什么的? praise包就一个功能:赞你! 2.praise包怎么搞? 2.1安装 直接安装: install.packages("praise") 从gith ...
- pointers on c (day 1,chapter1)
c语言的优先级 优先级 运算符 名称或含义 使用形式 结合方向 说明 1 [] 数组下标 数组名[常量表达式] 左到右 () 圆括号 (表达式)/函数名(形参表) . 成员选择(对象) 对象.成员名 ...
- 使用 Git 和 Visual Studio Online 进行版本控制
参考资料: 在开发计算机上设置 Git(配置.创建.克隆.添加) 关于 Git 和 Visual Studio Online 是什么请自行百度 转载请注明来源: http://www.cnblogs. ...
- BZOJ 1015 题解
1015: [JSOI2008]星球大战starwar Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝 ...
- SDL 五子棋游戏
http://www.jb51.net/article/79271.htm 1.定义窗口大小,棋盘大小 SDL_GetWindowSize()读取窗口大小, 由于棋盘是15*15格局,上下留白一行,在 ...