Home > Backend Development > PHP Tutorial > Detailed explanation of how thinkphp3.2 implements cross-controller calls to other modules

Detailed explanation of how thinkphp3.2 implements cross-controller calls to other modules

黄舟
Release: 2023-03-06 17:32:01
Original
1677 people have browsed it

This article mainly introduces the method of thinkphp3.2 to realize cross-controller to call other modules. It analyzes the common operation skills of thinkPHP cross-module and cross-controller calling methods in the form of examples. Friends in need You can refer to the following

The example of this article describes how thinkphp3.2 implements cross-controller calls to other modules. Share it with everyone for your reference, the details are as follows:

Thinphp has methods for calling each other in the front and backend, which can save duplicate content.

$hello = new \Admin\Common\Fun\hello();
$hello->hehe();
Copy after login

The same goes for calling methods in other places.

The module name can be omitted if it is in the same controller.

Such as calling a method of a certain class in common:

$hello = new \Common\Fun\hello();
$hello->hehe();
Copy after login

The framework provides the A() method across modules and controllers

class GoodsController extends Controller{
  function showlist(){
    // 实例化User控制器与调用方法
    $user = A('User');//通过快捷函数实例化控制器对象
    echo $user->number();//调用number()方法
  }
}
Copy after login

Calling demonstration:

A('User');  //跨控制器
A('Admin/User');  //跨模块
A('shop://Admin/User');  //跨项目
Copy after login

If it is still not convenient enough, the framework also provides the R() method to instantiate the class and call the method.

//User为控制器 number为方法
R('User/number');
R('Admin/User/number');
R('shop://Admin/User/number');
Copy after login

The effect is as follows:

class GoodsController extends Controller{
  function showlist(){
    // 实例化User控制器与调用方法
        A('User/number');//实例化user类并调用number方法
  }
}
Copy after login

The above is the detailed content of Detailed explanation of how thinkphp3.2 implements cross-controller calls to other modules. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template