项目框架为fastadmin
1、在application\tags.php绑定行为
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: liu21st <[email protected]> // +---------------------------------------------------------------------- // 应用行为扩展定义文件 return [ // 应用初始化 'app_init' => [ 'app\\common\\behavior\\Common', ], // 应用开始 'app_begin' => [], // 应用调度 'app_dispatch' => [ 'app\\common\\behavior\\Common', ], // 模块初始化 'module_init' => [ 'app\\common\\behavior\\Common', ], // 插件开始 'addon_begin' => [ 'app\\common\\behavior\\Common', ], // 操作开始执行 'action_begin' => [], // 视图内容过滤 'view_filter' => [], // 日志写入 'log_write' => [], // 应用结束 'app_end' => [], //消息通知,新添加的 'notice' => [ 'app\\common\\behavior\\Notice' ], ];
2、行为中的代码,在application\common\behavior\Common.php,添加代码
public function notice(&$request){ dump($request); }
3、调用头部添加 控制器头部添加
use think\HooK;//发送通知 $param=[ 'user_id' => 1, 'order_id' => 2, 'scene' =>3, ]; Hook::listen('notice', $param);
public function test(){
}
结果:
行为,相当于全局的函数,都是按同步执行的
标签:notice,demo,app,begin,common,behavior,thinkphp,行为,Common From: https://www.cnblogs.com/zhangzhijian/p/18231446