thinkphp3.2 implementing methods to invoke other modules across controllers

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

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.