Home > PHP Framework > ThinkPHP > How to use method a in thinkphp

How to use method a in thinkphp

藏色散人
Release: 2021-12-17 11:49:57
Original
2472 people have browsed it

The a method in thinkphp is used to instantiate the controller internally, and its calling format is "A('[project://][group/]module','controller layer name')", The usage method is like "$User = A('User');".

How to use method a in thinkphp

#The operating environment of this article: Windows 7 system, thinkphp v5.1 version, Dell G3 computer.

How to use method a in thinkphp?

Detailed explanation of ThinkPHP functions: Method A

A method is used to instantiate the controller internally. The calling format is:

A('[项目://][分组/]模块','控制器层名称')
Copy after login

The simplest Usage:

$User = A('User');
Copy after login

means instantiating the UserAction controller of the current project (the file corresponding to this controller is located in Lib/Action/UserAction.class.php). If the grouping mode is used and another one is to be instantiated Controllers grouped by Admin can be used:

$User = A('Admin/User');
Copy after login

also supports cross-project instantiation (the project directories must remain at the same level)

$User = A('Admin://User');
Copy after login

means instantiating the UserAction controller under the Admin project

Version 3.1 adds support for hierarchical controllers, so you can also use the A method to instantiate other controllers, for example:

$User = A('User','Event);
Copy after login

Instantiate the UserEvent controller (the corresponding file is located in Lib/Event/ UserEvent.class.php).

After instantiating a controller, you can call methods in the controller. However, what needs to be noted is that when calling across projects, if your operation method has special variables for the current controller There will be some unknown problems in operation, so generally speaking, officials recommend that the controller layer that requires public calls be developed separately without too many dependencies.

Recommended: "The latest 10 thinkphp video tutorials"

The above is the detailed content of How to use method a in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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