A function in thinkphp (Thinkphp3.2.3 version)

Source: Internet
Author: User

A function is a shortcut function for instantiating a controller in TP, which has the following syntax structure:

A (' Module/Controller ')// when the controller layer name is not controllers it is required to write A (' Module/controller ', ' Controller layer name ')

If the controller to be called is under the current module, it can also be written as follows:

A (' controller ')// or such a (' controller ', ' Controller layer name ')

Typically, an access controller is instantiated automatically, and the system is automatically instantiated based on the URL address of the controller that is accessed, and the associated action method is called. For example, we enter the following URL address:

http://Servername/home/index/index

The Indexcontroller class in home/controller/indexcontroller.class.php is now automatically instantiated. But if you need to call across a controller, you must instantiate it before calling:

Assuming that the home module is currently under the index controller
Instantiate the User controller for the Home module $Usernew \home\controller\usercontroller (); // Instantiate the Admin module's blog controller $Blog new \admin\controller\blogcontroller ();

The above code, if used with A function, can be simplified as follows:

$User // because the User controller is under the current module Home, the module name can be omitted $Blog = A (' Admin/blog ');

By default, the A method instantiates the default controller layer (controllers), and if you are instantiating other hierarchical controllers (such as Event), you can use:

// Suppose the current module is the Home module//instantiation Event Controller $User = A (' User ', ' event '$Blog = A (' Admin/blog ', ' event ');

The above code is equivalent to:

// instantiate the user event controller for the home module $User New \home\event\userevent (); // Instantiate the Admin module's Blog event controller $Blog new \admin\event\blogevent ();

A function in thinkphp (Thinkphp3.2.3 version)

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: info-contact@alibabacloud.com 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.