Home  >  Article  >  Backend Development  >  Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 09:51:21785browse

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46

[No operation processing]

Look at the pictures below:

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial The user accesses a non-existent operation—》Solution: Define an _empty() method for each controller to handle

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial The second solution: define a no-op

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial[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 1: Define an empty controller and empty module

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial Solution 2:

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial[Add function library files to the application]

In the Common folder, this is where our function library files are placed

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial【Module Grouping】

 1. Controller for group setting

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial 2. View templates need to be grouped

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial 3. Configuration variables need to be grouped

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial 4. Make configuration config.php

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial[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

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial There are many methods in a class, all of which require pre- and post-operations. How to solve this problem?

Solution:

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial[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

 A() method is used

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial Use of R() method

Getting Started with Thinkphp 2 (46), Getting Started with thinkphp 46_PHP Tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1014184.htmlTechArticleThinkphp Getting Started 2 (46), thinkphp Getting Started 46 [No Operation Processing] Look at the following picture: The user accesses a non-existent Operation》Solution: Define an _empty() method for each controller...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn