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 ...
随机推荐
- zepto下加载openbox弹出层
function fnOpenBox(objId,animateD,speed,tween,hide){ var oOpenBox = $(objId); oOpenBox.show(); oOpen ...
- hdu 4000Fruit Ninja 树状数组
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- delphi 对Tmemo指定的行写入
mmoMonitor:Tmemo; mmoMonitor.Lines.ValueFromIndex[0]:=aInfo ; procedure TMainForm.LogInfo(aInfo: str ...
- jquery toastr introduction
1.资源 http://www.jq22.com/jquery-info476 http://www.jq22.com/yanshi476 Nuget Install-Package toastr 官 ...
- enum枚举类型的使用
修饰符为public static enum,不用加final,否则提示错误. 枚举类的所有实例必须在枚举类中显式列出(,分隔,; 结尾).列出的实例系统会自动添加 public static fin ...
- BZOJ4605 : 崂山白花蛇草水
外层维护权值线段树,内层维护kd-tree. 修改的时候只往右儿子里插入,不平衡的时候替罪羊式重构. 查询的时候在外层线段树上走,在内层kd-tree上查询矩形内点数即可. 时间复杂度$O(q\log ...
- echarts.js 做图表的插件
<scripttype="text/javascript"src="{uiurl()}echarts/echarts.js"></script ...
- jQuery Ajax遍历表格,填充数据,将表格中的数据一条一条拼成Jason数组
$.ajax({ url: baseURL + "InvoiceSale/OnQuotaInvoiceSale", //点击核销单号时,点击核销时,交互的页面 ...
- [Cocos2D-x For WP8]Box2D物理引擎
物理引擎通过为刚性物体赋予真实的物理属性的方式来计算运动.旋转和碰撞反映.为每个游戏使用物理引擎并不是完全必要的—简单的“牛顿”物理(比如加速和减速)也可以在一定程度上通过编程或编写脚本来实现.然而, ...
- 【BZOJ1503】 [NOI2004]郁闷的出纳员 splay
splay模板题,都快把我做忧郁了. 由于自己调两个坑点. 1.删除时及时updata 2.Kth 考虑k满足该点的条件即r->ch[1]->size+1<=k && ...