The method of realizing mutual invocation between thinkphp controller _php instance

Source: Internet
Author: User
Tags php template smarty template

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

thinkphp How do the two-controller methods call each other in the same project? Thinkphp provides a () that allows the methods of the controller to be invoked with each other so that the code can be reused.

The official seems to have no documentation for the A () method, and now, for example, use a () method.

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

The code is as follows:

Copy 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 ();
}

So in the template you can loop alist to get the list of categories.

Description: The above code is WBlog3.0 (using thinkphp3.0 Core package) of the code version of the break, but I looked at the thinkphp3.1 and thinkph3.12 core package also retains a method.

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

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.