Thinkphp entry 2 (46)

Source: Internet
Author: User
: This article mainly introduces Thinkphp entry 2 (46). If you are interested in the PHP Tutorial, refer to it. [Empty operation processing]

See the following figure:

Actual situation: our User controller does not have the hello () method.

If an object accesses a method that does not exist in this class, it will access "magic method _ call ()"

A user accesses an operation that does not exist. Solution: define the _ empty () method for each controller to process the operation.

Solution 2: define an empty operation

[Empty module processing]

We use a class, but this class is not included yet.

We can use the automatic loading mechanism to process _ autoload (). If this automatic loading mechanism does not find this class, an error is returned.

Request an empty module

Solution 1: define an empty controller and module

Solution 2:

[Add a function library file to the application]

In the Common folder, it is the place where we put the library file.

[Module Group]

1. set the controller Group

2. View templates need to be grouped

3. configure variables to be grouped

4. configure config. php

[Pre-operation and post-operation]

When the methods in the controller are called, some additional work can be done before or after the call, which is called pre-operation and post-operation.

When we request this URL: http: // URL/index. php/Admin/Goods/zhanshi, where the action occurs when the method exists, App. class. in the exec () method of php

The preceding operations can be executed first when zhanshi () is executed.

The post operation can be executed after zhanshi () is executed.

There are many methods in a class that require both pre-and post-Operations. how can this problem be solved?

Solution:

[Cross-module call]

Instantiate a non-existent class, which will be automatically loaded through the _ autoload () mechanism.

Where is the _ autoload () of the tp framework? In Think. class. php

Instantiate A controller object using the () method

A ('Module controller') example: A ('Goods ')

A ('group/controller') for example: A ('Home/ucenter ');

A ('Project: // group/controller') for example: A ('shop: // home/ucenter ');

The A () method contains nested calls to the import () method. this method helps us obtain the corresponding controller and introduces require. A () method directly new the instantiated object by the way

R ("Project: // group/controller/Operation") method

It inherits the introduction, instantiation, and method calls of controllers.

R ('Module controller/operation') example: A ('Goods ')

R ('group/controller/operation') for example: A ('Home/Ucenter/members ');

R ('Project: // group/controller/operation') for example: A ('shop: // home/Ucenter/members ');

Call the () method in the R () method.

Call the import () method in the () method.

A () method usage

R () method usage

The above introduces Thinkphp entry 2 (46), including some content, and hopes to help those who are interested in PHP tutorials.

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.