thinkphp Introduction II (46)

Source: Internet
Author: User

"Empty Operation Processing"

Look at the following diagram:

Actual situation: Our user controller does not have the Hello () method

An object to access a method that does not exist in this class, then it accesses the "Magic Method __call ()"

User accesses a non-existent action-"FIX: Define a _empty () method for each controller to handle

Second workaround: Define an empty operation

"Empty module Handling"

We use a class, but now this class is not included in the include.

We can handle __autoload () through the automatic loading mechanism, and if the automatic loading mechanism does not find this class, it will error.

That is, request an empty module

Resolution one: Define an empty controller, empty module

Workaround Two:

"Add library files to your app"

Inside the common folder is where we put our function library files.

"Module grouping" 1.group settings for the controller

2.view templates need to be grouped

3.configuration variables need to be grouped

4.do configuration config.php

"Pre-action, post-operation"

The method inside the controller can do some extra work before or after the call, and it is called the pre-operation, the post-operation.

When we request this URL:/http//URL/index.php/admin/goods/zhanshi, in the case where the method exists, where this action occurs, App.class.php's exec () method inside

The inside of the pre-operation, can be executed in Zhanshi (), the first execution

The back operation inside can be executed after Zhanshi ()

There are many methods inside a class that require both pre-and post-operation, and how should they be resolved?

Solve:

"Cross-module invocation"

Instantiating a nonexistent class will pass the __autoload () automatic loading mechanism.

Where is the __autoload () of the TP frame? In Think.class.php

Instantiating a controller object with a () method

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

A (' Group/Controller ') For example: A (' home/ucenter ');

A (' Project://Group/controller ') For example: A (' shop://home/ucenter ');

There is a nested call to the import () method inside the A () method, which helps us to obtain the corresponding controller and introduce it require. A () method to instantiate an object by way of A Direct new

R ("Project://Group/Controller/operation") method

Is the introduction of the controller, the instantiation of the object, the invocation of the method to inherit well.

R (' Module controller/operation ') For 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 a () method inside the R () method

Call the import () method inside the A () method

The A () method uses

The R () method uses

thinkphp Introduction II (46)

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.