This article mainly introduces thinkphp3.2 methods for calling other modules across controllers, and analyzes common operations of thinkPHP cross-module and cross-controller calling methods in combination with examples, for more information about how to call other modules across controllers in thinkphp3.2, refer to this article. This article analyzes common thinkPHP cross-module and cross-controller call methods using examples, for more information, see
This example describes how thinkphp3.2 can call other modules across controllers. We will share this with you for your reference. The details are as follows:
In thinphp, the frontend and backend have mutual calling methods, which can save duplicate content.
$hello = new \Admin\Common\Fun\hello();$hello->hehe();
The same is true for calling methods elsewhere.
The module name in the same controller can be omitted.
For example, call the methods of a class in common:
$hello = new \Common\Fun\hello();$hello->hehe();
The framework provides A () method for cross-module and exaggerated controllers.
Class GoodsController extends Controller {function showlist () {// instantiate the User Controller and call method $ user = A ('user '); // use the shortcut function to instantiate the controller object echo $ user-> number (); // call the number () method }}
Call example:
A ('user'); // Cross-controller A ('admin/user'); // Cross-module A ('shop: // Admin/user '); // cross-project
If it is not convenient enough, the framework also provides the R () method, instantiate the class, and call the method.
// The User is the controller number as the method R ('user/number'); R ('admin/User/number'); R ('shop: // Admin/User/number ');
The effect is as follows:
Class GoodsController extends Controller {function showlist () {// instantiate the User Controller and call method A ('user/number'); // instantiate the User class and call the number method }}
The above is a detailed description of how thinkphp3.2 calls other modules across controllers. For more information, see other related articles in the first PHP community!