Home  >  Article  >  PHP Framework  >  How to use thinkphp behavior

How to use thinkphp behavior

藏色散人
藏色散人forward
2021-05-27 15:37:422082browse

下面由thinkphp框架教程栏目给大家介绍thinkphp行为如何使用,希望对需要的朋友有所帮助!

thinkphp 行为的使用

行为说简单一点就是程序执行到某一步会自动调用的一段操作,示例如下

第一步、添加行为标签位

$param['ids'] = $ids;
Hook::listen('event_reject',$param);

参数$param可选

 

第二步、行为绑定

在项目目录APP_PATH下的tags.php文件中进行绑定

return [
    'event_stop_publish'=>['app\\qikan\\behavior\\StopPublish']
];

第三步、在绑定的行为位置进行行为定义

namespace app\index\behavior;
class Test 
{
    public function app_init(&$param)
    {
        //$params 为引用传递
    }从
    
    public function app_end(&$param)
    {
    }    
}

The above is the detailed content of How to use thinkphp behavior. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete