thinkphp Controller to implement mutual call method, thinkphp controller _php Tutorial

Source: Internet
Author: User

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 {

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 (); true 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 ...

  • Related Article

    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: 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.