Home > PHP Framework > ThinkPHP > thinkphp cross-module calling method

thinkphp cross-module calling method

Release: 2020-04-03 10:30:31
forward
3174 people have browsed it

thinkphp cross-module calling method

How do we call across modules in thinkphp?

During the development process, methods of other modules are often called in the current module. This involves cross-module calls. We can also learn about the use of two shortcut methods, A and R.

$User = A("User"); // 实例化UserAction控制器对象
$User->importUser(); // 调用User模块的importUser操作方法
Copy after login

The A("User") here is a shortcut method, which is equivalent to the following code:

import("@.Action.UserAction");
$User = new UserAction();
Copy after login

In fact, in this example, there is a simpler call than the A method Methods, for example:

R("User","importUser"); // 远程调用UserAction控制器的importUser操作方法
Copy after login

The above is only called in the current project. If you need to call methods between multiple projects, the same can be done:

$User = A("User","App2"); // 实例化App2项目的UserAction控制器对象
$User->importUser(); 
// 远程调用App2项目的UserAction控制器的importUser操作方法
R("User","importUser","App2");
Copy after login

An example of mine:

A project is divided into two groups: admin and home

home is the group by default:

When instantiating the module (the current location is the IndexAction class in admin Instantiated in the index method)

 import("@.Action.Home.UserAction");
$User=new UserAction();
$User->show();
$User->add();
Copy after login

Note: The method called must be public

Recommended tutorial: thinkphp tutorial

The above is the detailed content of thinkphp cross-module calling method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:oschina.net
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