Wemall7.0 open source system, developed based on thinkphp5, supports composer, optimizes the core, reduces dependencies, and is based on new architectural ideas and namespaces.
The operating environment of ThinkPHP5 requires PHP5.4 or above.
Feature list
Home page=》System home page
Settings=》Site settings, SMS configuration, email configuration
WeChat=》WeChat configuration, WeChat menu, customized replies, template messages, multiple customer service settings, WeChat printer
Content=》Article classification, article list
Template=》Template settings, email template, SMS template
User => Administrator user group, administrator list, user list, member list
Plug-ins => Plug-in management, plug-in store
Help=》Use help
...
composer require qingyuexi/think-addons
'addons'=>[
// 可以定义多个钩子
'testhook'=>'putongdemodemo' // 键为钩子名称,用于在业务中自定义钩子处理,值为实现该钩子的插件,
// 多个插件可以用数组也可以用逗号分割
]
Or create a new addons.php
in the applicationextra directory with the following content:
<?php
return [
// 可以定义多个钩子
'testhook'=>'putongdemodemo' // 键为钩子名称,用于在业务中自定义钩子处理,值为实现该钩子的插件,
// 多个插件可以用数组也可以用逗号分割
]
The created plug-in can be used in the view or in the PHP business
After the installation is complete, when you access the system, a directory named addons
will be generated in the project root directory, and the required plug-ins will be created in this directory.
Write an example below:
Create putong directory in addons directory
Create the config.php class file in the putong directory. The plug-in configuration file can be omitted.
<?php
return [
'name' => 'putong',
'title' => 'putong',
'description' => 'putong类插件',
'status' => 1,
'author' => '清月曦'
];
Create a demo directory in the putong directory under the addons directory
Create the Demo.php class file in the test directory. Note: The first letter of the class file must be capitalized
<?php
namespace addonsputongdemo; // 注意命名空间规范
use thinkAddons;
/**
* 插件测试
* @author byron sampson
*/
class Demo extends Addons // 需继承thinkaddonsAddons类
{
// 该插件的基础信息
public $info = [
'name' => 'test', // 插件标识
'title' => '插件测试', // 插件名称
'description' => 'thinkph5插件测试', // 插件简介
'status' => 0, // 状态
'author' => 'byron sampson',
'version' => '0.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');
}
}
Create the config.php class file in the test directory. The plug-in configuration file can be omitted.
<?php
return [
'name' => 'demo',
'title' => 'demo',
'description' => 'demo插件',
'status' => 1,
'url' => true,
'author' => '清月曦',
'version' => '0.1'
];
Create the info.html template file in the demo directory, which is the corresponding template file when the hook uses the fetch method.
<h1>hello tpl</h1>
如果插件中需要有链接或提交数据的业务,可以在插件中创建controller业务文件,
要访问插件中的controller时使用addon_url生成url链接。
如下:
<a href="{:addon_url('putong://demo/admin/index')}">link demo</a>
格式为:
demo为插件名,admin为controller中的类名,index为controller中的方法
Create the controller directory in the test directory, and create the Action.php file in the controller directory. The usage of the controller class is consistent with the controller in tp5.
<?php
namespace addonsputongdemocontroller;
class Admin
{
public function index()
{
echo 'hello link';
}
}
If you need to use the view template, you need to inherit the
thinkaddonsController
class template file. The location of the template file is the view in the plug-in directory. The rules are consistent with the view rules in the module.
<?php
namespace addonsputongdemocontroller;
use thinkaddonsController;
class Admin extends Controller
{
public function index()
{
return $this->fetch();
}
}
After creating the plug-in, you can use the hook in the plug-in in normal business. When using the hook, the second parameter can be omitted.
<div>{:hook('testhook', ['id'=>1])}</div>
It can be used anywhere in the normal process of thinkphp5
hook('testhook', ['id'=>1])
tp5
- addons
-- putong
--- demo
---- controller
----- Admin.php
---- view
---- action
----- link.html
--- config.php
--- info.html
--- Demo.php
- application
- thinkphp
- extend
- vendor
- public
The wemall7 open source version is released under the Apache2 open source license and is available for free use. The copyright information of the third-party source code and binary files included in this project is separately marked. Copyright Copyright © 2016-2017 by wemallshop.com (http://www.wemallshop.com) All rights reserved.