How to call other modules across controllers using thinkphp3.2

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.