THINKPHP5 's controller calls its own module and calls methods of other modules

Source: Internet
Author: User

In the case of user, call user.php's Get_number () method

First, whether it is to call their own modules or other modules app\model\user.php the same wording

1<?PHP2 3 namespace App\index\model;4  UseThink\model;5 6 classUserextendsModel7 {8      Public functionGet_member () {9         return3;Ten     } One}

Second, the user controller calls the user module (that is, the controller calls itself module)

1<?PHP2 namespace App\index\controller;3  Usethink\db;4  UseThink\controller;5  UseApp\index\model\user asUsers;6 classUserextendsController7 {8      Public functionWudi () {9         $user=NewUsers ();Ten         $user=$user-Get_member (); One         Echo $user; A     } -}

Third, the index controller calls the user module (that is, the controller calls other modules)

<?phpnamespace App\index\controller; Usethink\db; UseThink\controller; UseApp\index\model\user;classIndexextendscontroller{ Public functionWudi () {$user=NewUser (); $user=$user-Get_member (); Echo $user; }}

Iv. Analysis

The controller calls itself module because the name is user, there will be an error.

To prevent this, rename the user to

Rename Syntax Yes (User as new name)

THINKPHP5 's controller calls its own module and calls methods of other modules

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.