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.