Decryption ThinkPHP3.1.2 version of the standalone grouping feature application _php tutorial

Source: Internet
Author: User
Thinkphp's grouping function is a very useful feature that is widely used by developers, which solves the problem of too many MVC layered files in large-scale projects, which makes them difficult to manage.

The independent grouping function added by the ThinkPHP3.1.2 version provides a new solution for this kind of problem, which is more suitable for the modular development mode. We understand this feature in this context.

1. Overview

The independent grouping function does not affect the operation of the original grouping mode, and the original grouping mode only needs to move the directory structure to complete the independent grouping mode upgrade without any application code changes.

And the new independent grouping can be very convenient to handle and move independently, you can get rid of the original common group files scattered in the various directories under the puzzle.

The separate group URL access is the same as the original normal grouping, and the configuration grouping list is still configured with the App_group_list parameter. Setting the default grouping takes the Default_group parameter. For example:

' App_group_list ' = ' home,admin ', ' default_group ' and ' Home ',

Although the new independent group can completely replace the original normal grouping mode, but in order to take into account the original group project smooth upgrade, this new version adds a configuration parameter:

The App_group_mode is used to configure the grouping mode, which defaults to 0 for the original normal grouping mode, and if set to 1, the standalone grouping mode is enabled.
Whether you need to upgrade to a standalone grouping mode is entirely up to you, and I believe you will have a wise choice when you read the following.

2. Directory structure

When you enable stand-alone grouping mode, you need to create a stand-alone grouping directory under the project directory, which can be configured by the project configuration file through the App_group_path parameter, and the default value is modules. If we do not make any changes, under the modules directory is the sub-directory of each grouping, each group is completely independent, including models, controllers, views, configuration and function files, etc., you can easily implement the grouping of moving and unloading.
The standard stand-alone grouping directory structure is (in the case of a home grouping):

─home Home grouping directory ├─common grouping function directory ├─conf grouping configuration directory ├─lang grouping Language pack directory ├─action grouping Action Controller directory ├─model grouping model catalog ├─widget grouping Widget directory ├─org Group Extension Class Library directory ├─ ... Other hierarchical Catalogs └─tpl Group template catalogs

( Note: The directory structure of the stand-alone grouping needs to be created manually now )
It can be seen that independent groups have basically the same structure as other independent projects except for the entry files.
To upgrade from the original normal group to the standalone group, simply add in the project configuration file:

' App_group_mode ' =>1

Then the original project Lib directory under the corresponding grouping of MVC files, as well as the grouping of functions, configuration and language (if any) files in turn against the above independent grouping directory structure into the corresponding directory.

3. Public Documents

With independent grouping, the original project Lib directory is designed as a grouping common class library file, if you need to call the public action or model class for multiple independent groupings (in fact, other hierarchical controllers and models), You can put these public classes into the corresponding directory under the project's Lib directory (the actual upgrade process, these public class library files basically keep the directory structure unchanged, so there is no need to move).
The group's public class library files do not need to be loaded manually, and the automatic loading mechanism is used.
Therefore, the actual project directory structure with independent grouping mode is as follows:

├─index.php   Project portal File ├─common project Common Files directory ├─conf project configuration directory ├─lang Project language directory ├─modules stand-alone grouping directory │├─home Home Group directory (stand-alone grouping directory structure reference front) │├─ Admin Admin Group Directory │└─ ... Other Group Directory ├─lib group Common Class Library Directory │├─action Public action Class Library directory │├─behavior common behavior Class Library directory │├─model public model class Library directory │└─ ... Other public class Library directory ├─runtime project run-time catalog │├─cache template cache directory │├─data data cache directory │├─logs log file directory │└─temp temporary cache directory


4. template file

The template file for the standalone grouping is moved from the project's TPL directory to the TPL directory of the standalone grouping directory, and the original template grouping subdirectory is no longer needed, for example:

After moving to the TPL directory under the standalone group, it should be:

Tpl/index/index.html

The template theme feature is still supported.

5. Calling the class library

Standalone grouping when importing a class library, the use method is basically the same as importing the Project class library, for example:

Import (' @. Action.testaction '); Import the action/testaction.class.php import (' @.org.util.image ') under the current grouping; Import the org/util/image.class.php under the current grouping

Independent groupings do not consider interactions and calls between multiple groupings, only public class libraries can be called.
If you have to call another grouped class library instead of a public class library design, you can use:

However, with separate groupings, both the A method and the R method and the D method do not support cross-grouping calls.

http://www.bkjia.com/PHPjc/825443.html www.bkjia.com true http://www.bkjia.com/PHPjc/825443.html techarticle thinkphp's grouping function is a very useful feature that is widely used by developers, which can solve the problem of too many MVC layered files in large-scale projects, which leads to difficult to manage ...

  • 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.