A method for mutual invocation between thinkphp controllers

Source: Internet
Author: User
This article mainly introduces the method of mutual call between thinkphp controller, mainly through a () method to achieve this function, can effectively improve the code reuse, very practical value, the need for friends can refer to the next

This paper describes the method of mutual invocation between thinkphp controllers. Share to everyone for your reference. The implementation method is as follows:

thinkphp How do the methods of two controllers call each other in the same project? Thinkphp provides a () that allows the methods of the controller to call each other, allowing the code to be reused.

The official seems to have no correlation with the A () method using the documentation, now, for example, using the A () method.

There are two controllers, Columnsaction and newsaction. Ncatlist () is the Columnsaction classification list method, and now I want to call the Ncatlist () method in the controller newsaction.

The code is as follows:

Copy the Code code as follows:

Class Columnsaction extends action{public   function Ncatlist () {      $Columns =new Model;                           $News = M ("News");      $list = $Columns->query ("Select Concat (Colpath, '-', colId) as Bpath, Colid,colpid,colpath, Coltitle, Description,ord From ". C (' Db_prefix '). " Columns where typeid=1         ORDER by Bpath, colId ");                                           $this->assign (' alist ', $list);             }  }  Class Newsaction extends Commonaction {            //Home public      Function index () {     $Columns =a ("Columns");     $Columns->ncatlist ();  }

This way you can loop alist to get a list of categories in the template.

Description: The code above is WBlog3.0 (using THINKPHP3.0 's core package), but I've looked at the thinkphp3.1 and thinkph3.12 core packages to keep the A 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.