Brief introduction of plug in controller function of ThinkPHP3.2. 2
- 2021-07-07 06:44:46
- OfStack
Since version 3.2. 2, ThinkPHP supports the call of plug-in controller, and can access the controller defined by a plug-in in the module through a more convenient URL address.
When the plug-in controller variable is passed in URL, the action method in the plug-in controller is automatically navigated.
The variable of the plug-in controller is set by the parameter VAR_ADDON, which defaults to addon. For example, we passed in URL:
http://serverName/Home/info/index/addon/SystemInfo
Because the addon parameter is passed in, the User controller here is not the original one
Home/Controller/InfoController.class.php
Instead, call the InfoController controller of the SystemInfo plug-in (located under the Home/Addon directory), and the file is located in the
Home/Addon/SystemInfo/Controller/InfoController.class.php
The definition of plug-in controller itself is similar to that of ordinary access controller 1, for example:
namespace Home\Addon\SystemInfo\Controller;
class InfoController extends \Think\Controller{
public function index(){
echo 'Addon SystemInfo';
}
}
In this way, we are visiting
http://serverName/Home/info/index/addon/SystemInfo
Will output when
Addon SystemInfo
If our plug-in directory is not Addon, but Plugin, we need to define it in the configuration file:
'VAR_ADDON' => 'plugin'
Then accessing the URL address becomes
http://serverName/Home/info/index/plugin/SystemInfo
It should be noted that at present, plug-in controllers only support plug-in controller access of modules, and do not support global public plug-ins.