Home  >  Article  >  Backend Development  >  ThinkPHP A method example explanation_PHP tutorial

ThinkPHP A method example explanation_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:24:21727browse

ThinkPHP’s A method is used to instantiate the controller internally, and its calling format is:

A('[project://][group/]module','controller layer name')

Easiest usage:

$User = A('User');

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 adopted and you want to instantiate another Admin grouped controller, you can use :

$User = A('Admin/User');

Cross-project instantiation is also supported (project directories must remain at the same level)

$User = A('Admin://User');

represents instantiating the UserAction controller under the Admin project

ThinkPHP 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);

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, it should be noted that when calling across projects, if your operation method has special variable operations for the current controller, there will be some unknowns. Therefore, generally speaking, officials recommend that the controller layer that requires public calls be developed separately without too many dependencies.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825505.htmlTechArticleThinkPHP’s A method is used to instantiate the controller internally, and its calling format is: A('[project: //][Group/]Module','Controller layer name') The simplest usage: $User = A('User'); represents the instance...
Statement:
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