1、新建 application/api/behavior/TestHook.php 文件
<?php
namespace app\api\behavior;
class TestHook
{
/**
* Description: 这是默认的方法,当其他标签找不到时调用此方法
* @return {[type]} [description]
*/
public function run($params)
{
echo '这是默认的方法';
}
/**
* Description: 绑定上级
* @param {[type]} $params [description]
* @return {[type]} [description]
*/
public function bindParent($params)
{
echo '自定义的方法-bindParent';
}
}
2、在 application/tags.php 文件里添加:
'aaa' => [
'app\\api\\behavior\\TestHook'
],
// 调用 bindParent 方法
'bind_parent' => [
'app\\api\\behavior\\TestHook'
],
3、在方法中调用钩子:
use think\Hook;
Hook::listen('aaa', []); // 调用 run 方法
Hook::listen('bind_parent', []); // 调用 bindParent 方法
1万+




被折叠的 条评论
为什么被折叠?



