Home > Backend Development > PHP Tutorial > ThinkPHP3.2.2 plug-in controller function

ThinkPHP3.2.2 plug-in controller function

不言
Release: 2023-03-30 09:36:01
Original
1268 people have browsed it

This article mainly introduces how to use the plug-in controller function newly supported by ThinkPHP3.2.2. It is very detailed and is recommended to friends here.

Version 3.2.2 starts to support the calling of plug-in controllers, and you 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 the URL, the operation method in the plug-in controller will be automatically located.

The variables of the plug-in controller are set by the parameter VAR_ADDON. The default is addon. For example, we pass in the URL:

Copy code The code is as follows:

http://serverName/Home/info/index/addon/SystemInfo
Copy after login
Copy after login

Since the addon parameter is passed in, the User controller here is not the original one

Copy code The code is as follows:

Home/Controller/InfoController.class.php
Copy after login

Instead, the SystemInfo plug-in is called (located at InfoController controller under the Home/Addon directory), the file is located at

Copy code The code is as follows:

Home/Addon/SystemInfo/Controller/InfoController.class.php
Copy after login

The definition of the plug-in controller itself and the ordinary access controller Same, for example:

Copy code The code is as follows:

namespace Home\Addon\SystemInfo\Controller;
 class InfoController extends \Think\Controller{
    public function index(){
        echo 'Addon SystemInfo';
    }
 }
Copy after login

In this way, we are accessing

Copy code The code is as follows:

http://serverName/Home/info/index/addon/SystemInfo
Copy after login
Copy after login

will be output when
Addon SystemInfo
If our plug-in directory is not Addon, but Plugin, then it needs to be defined in the configuration file:

Copy Code The code is as follows:

'VAR_ADDON'    =>    'plugin'
Copy after login

Then accessing the URL address becomes

Copy code The code is as follows:

http://serverName/Home/info/index/plugin/SystemInfo
Copy after login

Note: Currently the plug-in The controller only supports module plug-in controller access and does not yet support global public plug-ins.

Note: This usage is only for version 3.2.2 downloaded from the official website. Some detailed adjustments will be made in the future, including defining the location of plug-ins and so on.

Related recommendations:

Behavior extensions and plug-ins in ThinkPHP

The above is the detailed content of ThinkPHP3.2.2 plug-in controller function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template