ThinkPHP A method example

Source: Internet
Author: User

The A method of ThinkPHP is used to instantiate the Controller internally. The call format is as follows:

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

The simplest usage:

$ User = A ('user ');

The UserAction controller of the current project is instantiated (the file corresponding to this controller is located in Lib/Action/UserAction. class. php). If you use the grouping mode and want to instantiate the controller of another Admin group, you can use:

$ User = A ('admin/user ');

Cross-Project instantiation is also supported (the project directory must be at the same level)

$ User = A ('admin: // user ');

The UserAction Controller under the Admin project is instantiated.

The version 3.1 of ThinkPHP adds support for hierarchical controllers, so other controllers can be instantiated using the method, for example:

$ User = A ('user', 'event );

Instantiate the UserEvent controller (the corresponding file is in Lib/Event/UserEvent. class. php ).
After the controller is instantiated, you can call the methods in the Controller. However, when calling a controller across projects, if your operation method has special variable operations for the current controller, there will be some unknown issues, so in general, the official recommendation is to develop a public call controller layer separately, do not have too many dependencies.

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.