During the development process, the current module often calls methods of other modules, which involves cross-module calls, we can also learn how to use ThinkPHP to extract the ThinkPHP manual for shortcuts A and R (cross-module ).
During the development process, the current module often calls methods of other modules. this involves cross-module calls. we can also learn how to use shortcuts A and R.
$ User = A ("User"); // instantiate the UserAction controller object
$ User-> importUser (); // call the importUser operation method of the User module
Here, A ("User") is A shortcut, which is equivalent to the following code:
Import ("@. Action. UserAction ");
$ User = new UserAction ();
In fact, there are more simple calling methods than method A in this example, for example:
R ("User", "importUser"); // remotely call the importUser operation method of the UserAction controller
The above is only called in the current project. if you need to call methods between multiple projects, you can do the same:
$ User = A ("User", "App2"); // instantiate the UserAction controller object of the App2 project
$ User-> importUser ();
// Remotely call the importUser operation method of the UserAction controller of App2 project
R ("User", "importUser", "App2 ");
My example:
A project is divided into two groups: admin and home.
Home is a group by default:
When instantiating the module (the current position is instantiated in the index method of the IndexAction class in admin)
Import ("@. Action. Home. UserAction ");
$ User = new UserAction ();
$ User-> show ();
$ User-> add ();