Thinkphp entry 2 (46) and thinkphp entry 46

Source: Internet
Author: User
Tags autoload

Thinkphp entry 2 (46) and thinkphp entry 46
[Empty Operation Processing]

See the following figure:

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

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

 

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.