thinkphp Development Framework function Detailed: R method

Source: Internet
Author: User
Keywords Development framework function R method thinkphp
Tags aliyun array class data development development framework example framework

The R method is used to invoke the operation method of a controller, and is further enhanced and supplemented by a method.
Call format for the R method:
R (' [item://][Grouping/] Module/operation ', ' parameter ', ' Controller layer name ')
For example, we define an action method that is:

Class&http://www.aliyun.com/zixun/aggregation/37954.html ">NBSP;     Useraction extends Action {public Function detail ($id) {return M (' User ')->find ($id); } }

Then you can call this action method in other controllers by using the R method (the general R method is used to call across modules)

$data = R (' User/detail ', Array (' 5 '));

Represents the detail method that invokes the user controller (the detail method must be a public type), and the return value is a user data with Query ID 5. If you want to invoke an action method that has no arguments, the second argument can be left blank and used directly:

$data = R (' User/detail ');

You can also support cross grouping and project calls, such as:

R (' Admin/user/detail ', Array (' 5 '));

Represents the detail method that invokes the user controller under the Admin group.

R (' Admin://user/detail ', Array (' 5 '));

Represents the detail method that invokes the user controller under the Admin project.
The official advice is not to make too many calls on the same floor, which can cause logical confusion, the part of the public call should be encapsulated into a separate interface that can be used to add a single controller layer to the interface call by using 3.1 of the new feature multilayer controllers, for example, we add an API controller layer,

Class Userapi extends Action {public Function detail ($id) {return M (' User ')->find ($id); } }

Then, use the R method to call the

$data = R (' User/detail ', Array (' 5 '), ' Api ');

In other words, the third parameter of the R method supports the controller layer that specifies the call.
Also, the R method invokes the action method to support the operation suffix setting C (' Action_suffix '), and if you set the action method suffix, you still do not need to change the way the R method is invoked.

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.