Home > Article > Backend Development > Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial
Look at the pictures below:
The user accesses a non-existent operation—》Solution: Define an _empty() method for each controller to handle
The second solution: define a no-op
[Empty module processing]
We use a class, but this class has not been included yet.
We can handle __autoload() through the automatic loading mechanism. If the automatic loading mechanism does not find this class, an error will be reported.
Is requesting an empty module
Solution 2:
[Add function library files to the application]
In the Common folder, this is where our function library files are placed
【Module Grouping】
2. View templates need to be grouped
3. Configuration variables need to be grouped
4. Make configuration config.php
[Pre-operation, post-operation]
When the method in the controller is called, it can do some additional work 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 does this action occur if the method exists? Inside the exec() method of App.class.php There are many methods in a class, all of which require pre- and post-operations. How to solve this problem?
Solution: [Cross-module call]
Instantiating a non-existent class will be automatically loaded through the __autoload() mechanism. Where is __autoload() of tp framework? in Think.class.php Instantiate the controller object through the 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 in the A() method. This method helps us obtain the corresponding controller and require it to be introduced. The A() method directly instantiates the object with new R("project://group/controller/action") method It inherits the introduction of controllers, instantiated objects, and method calls. 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 the A() method in the R() method The import() method is called in the A() method Use of R() method
A() method is used