Problem analysis
Today in the use of onethink, found that even can invoke the controller inside the plug-in, such as the index.php?s=/Addons/execute/_addons/EditorForAdmin/_controller/Upload/_action/ke_upimg.html
representative called the addons/editorforadmin/controller/uploadcontroller.class.php in Ke_ Upimg, feel with so long TP, has not done so, it is necessary to delve into, it can do this reason. By analyzing the route, it is found that the Execute method in/home/addonscontroller.class.php is actually called, and then in the Execute method, the Uploadcontroller class is instantiated and the Ke_upimg method is called. In fact, it is equivalent to let the home/addonscontroller.class.php class do a proxy, _addons/EditorForAdmin/_controller/Upload/_action/ke_upimg.html
as a parameter. After figuring this out, it's quite handy to write your own plugin later.
AddonsController.class.php file
class addonscontroller extends Controller{ protected $addons=NULL; Public function execute($_addons = null, $_controller = null, $_action = NULL){ ifC' url_case_insensitive ')){$_addons= Ucfirst (Parse_name ($_addons,1));$_controller= Parse_name ($_controller,1); }if(!Empty($_addons) &&!Empty($_controller) &&!Empty($_action)){$Addons= A ("Addons://{$_addons}/{$_controller}"),$_action(); }Else{$this->error (' no plugin name, CONTROLLER or operation specified! '); } }}
Define your own plug-in
I defined the controller LogController.class.php in the next Onethink/addons/calendar/controller, for example,
<?php// +----------------------------------------------------------------------// | Copyright (c) http://blog.csdn.net/hsd2012 All rights reserved.// +----------------------------------------------------------------------// | Author:dequan// +----------------------------------------------------------------------// | Time:2016-06-15// +----------------------------------------------------------------------namespace Addons\Calendar\Controller; Use Think\Controller; class logcontroller extends Controller{ /** * Add log * * Public function addlog(){Var_dump (' Addlog '); }}
So how do you access the controller? Use the following address, because I am binding the model home in the portal file, so when called, you do not need to add the model name.
localhost/index.php?s=/Addons/execute/_addons/Calendar/_controller/log/_action/addLog.html
Execution results
thinkphp Execution Process
thinkphp the execution process is simplified, it can be summed up as follows
index.php-->think.class.php ——->app.class.php
1. Initialize parameters (define constants, load some configuration files), define exceptions, errors, automatic file loading, define storage methods
2. Path parsing and the corresponding filtering
3. Create the requested Controller object
4. Obtain the requested method by reflection, determine its properties, and get all the parameters of the method.
5. Obtain the requested controller class by reflection, determine whether it defines a ‘_before_‘.$action
method, determine the method property, or call the method if it is a public property.
6. Invoking the requested method through reflection
7. Determine if it defines a ‘_after_‘.$action
method, determine the method property, or call the method if it is a public property.
8. For the above behavior, the corresponding behavior hooks are defined in thinkphp, and the corresponding behavior hooks are invoked before or after the execution of the behavior.
Note
Plug-in development can refer to the following URLs
http://blog.csdn.net/hsd2012/article/details/51658880
Controller access Path control in Onethink plug-in