The method of mutual call between thinkphp Controller, thinkphp Controller
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.
It is hoped that this article will be helpful to everyone's thinkphp framework design.
thinkphp how to invoke another method of the module in a method in one module? Can the Thinkphp method pass parameters?
Direct $this function (); You can have it. The action as a Class view, flexible use, parameters can also be added, but the declaration of the time as far as possible to add the default parameters, in order to avoid the call through the module when the alarm error without parameters.
Thinkphp the current action method calls the value of another action method
The acquisition ID is encapsulated in another way, such as protected function getId () {
$id =//Get method
return $id
}
Other methods are called $id = $this->getid ();
http://www.bkjia.com/PHPjc/904010.html www.bkjia.com true http://www.bkjia.com/PHPjc/904010.html techarticle thinkphp Controller to implement the method of mutual invocation, thinkphp controller in this paper, we describe the method of mutual invocation between thinkphp controllers. Share to everyone for your reference. Concrete implementation ...