Yii源码阅读笔记(二十五)
2024-09-25 22:22:46
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;//返回结果 }
最新文章
- android 真机调试出现错误 INSTALL_FAILED_INSUFFICIENT_STORAGE 的解决方法。
- 一种快速刷新richedit中内嵌动画的方法的实现
- Java web--反射(解刨)
- socket通信入门
- 【转】PowerDesigner使用方法小结
- setInterval小问题
- Bootstrap入门一:Hello Bootstrap
- DB2死锁解决办法
- 【原】SparkContex源码解读(一)
- linux bash shell中case语句的实例
- 【开源java游戏框架libgdx专题】-08-中文显示与绘制
- puppet cert maintain
- Candy 解答
- 从一个实例,看new FunctionName()的内部机制
- 【Android基础】eclipse常用快捷键
- 前端MVVM框架:Knockout.JS(一)
- Another kind of Fibonacce(矩阵快速幂,HDU3306)
- Qt学习之路MainWindow学习过程中的知识点
- thinkinginjava学习笔记04_初始化与清理
- 利用PowerUpSQL攻击SQL Server实例
热门文章
- 《用delphi开发共享软件》-15.2桌面提示器
- 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles
- LightOJ1018 Brush (IV)(状压DP)
- underscore.js依赖库函数分析二(查找)
- display:none 与 opacity:0
- [Noi2015]软件包管理器 题解
- CentOS 6.4 查看每个进程的网络流量
- APP测试流程
- IOS 蓝牙相关-app作为外设被连接的实现(3)
- css去掉使用bootstrap框架后打印网页时预览效果下的超链接