# thinkphp-addons **Repository Path**: fallcat/thinkphp-addons ## Basic Information - **Project Name**: thinkphp-addons - **Description**: addons package for thinkphp5.1.x - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: master - **Homepage**: http://www.shareboxi.com - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 0 - **Created**: 2019-01-07 - **Last Updated**: 2022-03-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # thinkphp-addons #### 安装 composer require hawk/thinkphp-addons dev-master #### 介绍 addons package for thinkphp5.1.x ## 配置 ### 公共配置 > 在根目录下的config文件夹里创建addons.php > 安装插件后也可自动生成并更新 ``` 'addons'=>[ // 是否自动读取取插件钩子配置信息(默认是关闭) 'autoload' => false, // 当关闭自动获取配置时需要手动配置hooks信息 'hooks' => [ // 可以定义多个钩子 'testhook'=>'test' // 键为钩子名称,用于在业务中自定义钩子处理,值为实现该钩子的插件, // 多个插件可以用数组也可以用逗号分割 ] ] ``` ## 创建插件 > 创建的插件可以在view视图中使用,也可以在php业务中使用 安装完成后访问系统时会在项目根目录生成名为`addons`的目录,在该目录中创建需要的插件。 下面写一个例子: ### 创建test插件 > 在addons目录中创建test目录 ### 创建钩子实现类 > 在test目录中创建Test.php类文件。注意:类文件首字母需大写 ``` 'test',// 插件标识 'title' => '插件测试',// 插件名称 'description' => '插件测试',// 插件简介 'author' => 'shareboxi.com', 'version' => '2.0', 'plugin_url' => 'http://www.shareboxi.com', 'author_url' => 'http://www.shareboxi.com', 'status' => 1// 状态 ]; /** * 插件安装方法 * @return bool */ public function install() { return true; } /** * 插件卸载方法 * @return bool */ public function uninstall() { return true; } /** * 实现的testhook钩子方法 * @return mixed */ public function testhook($param) { // 调用钩子时候的参数信息 print_r($param); // 当前插件的配置信息,配置信息存在当前目录的config.php文件中,见下方 print_r($this->getConfig()); // 可以返回模板,模板文件默认读取的为插件目录中的文件。模板名不能为空! return $this->fetch('info'); } } ``` ### 创建插件配置文件 > 在test目录中创建config.php类文件,插件配置文件可以省略。 ``` [ 'title' => '是否显示:', 'type' => 'radio', 'options' => [ '1' => '显示', '0' => '不显示' ], 'value' => '1' ] ]; ``` ### 创建钩子模板文件 > 在test目录中创建widget.html模板文件,钩子在使用fetch方法时对应的模板文件。 ```