This article mainly introduces the thinkphp3.2 implementation of the cross-controller calls to other modules, analysis of the thinkphp cross-module, cross-controller call method of common operation skills, the need for friends can refer to the following
This article describes a method that thinkphp3.2 implements to invoke other modules across controllers. Share to everyone for your reference, as follows:
In the thinphp, there are calls to each other in the foreground, which eliminates duplication of content.
$hello = new \admin\common\fun\hello (); $hello->hehe ();
The same approach to calling other places.
If it is in the same controller, the module name can be omitted.
such as calling the method of a class inside common:
$hello = new \common\fun\hello (); $hello->hehe ();
A () method for cross-module, Kua-Controller is provided in the framework.
Class Goodscontroller extends controller{ function showlist () { //instantiate user controller and call method $user = A (' user ');// Instantiate the Controller object with a shortcut function echo $user->number ();//Call Number () method }}
Invoke Demo:
A (' User '); Cross controller A (' Admin/user '); Cross Module A (' Shop://admin/user '); Cross-project
If it's not convenient, the framework also provides the R () method, instantiates the class, and invokes the method.
The User is the controller number for 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 User controller with call method A (' user/number ');// Instantiate the user class and call the number method }}