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