Thinkphp5.0 methods for automatically generating modules and directories

Source: Internet
Author: User
This article mainly introduced the Thinkphp5.0 automatic generation module and the directory method, the simple analysis Thinkphp5.0 structure, the directory, the creation and the operation method, the need friend can refer to the next

In this paper, we describe the method of Thinkphp5.0 automatic generation of modules and directories. Share to everyone for your reference, as follows:

Thinkphp5.0 has been released for some time, it is said that the performance has been greatly improved, according to the official word, the ThinkPHP5.0 version is a subversion and refactoring version, the use of new architectural ideas, introduced a lot of new PHP features, optimized the core, reduced reliance, realized the real lazy loading, and for the development of the API to do a large Optimization of the volume. It's time to download a copy and study it. Today, we mainly talk about its automatic creation of modules and directories.

Thinkphp5.0 Auto-generated module is more ThinkPHP3.2, there is a great change.

Again, the main discussion is Thinkphp5.0 generation module.

Preparatory work

First from the official download ThinkPHP5.0, after downloading the file structure as follows:

Keep all other directories and files in thinkphp directory deleted (can be transferred to other places for later use)

Start building a project now requires a catalog

thinkphp3.2 Creating a directory looks simple, but thinkphp5.0 is more flexible. It is not easy to think of good is to make complex things simple, mediocrity is to make simple things complicated, stupid is to make simple things simpler, complex things become more complex.

1. Create the portal file index.php, although the official emphasis on the entrance file location, can be placed at will, but in order to facilitate learning, or placed in the root directory

Application Portal file define (' App_path ', ' application/'); Define the project path, and there is no difference between the previous 3.2 versions define (' App_auto_build ', true); Turn on auto generate define (' App_debug ', true);//Open Debug mode define (' module ', ' module ');//load frame boot file require ' thinkphp/start.php ';/ Execute application \think\app::run ();

In fact, I personally think, TP official why do not put, the implementation of the program \think\app::run (); In the start.php directory? Finally, it is found that the original TP5.0 introduced a define (' App_auto_run ', true); constants, when the change constants are defined on the index.php page, the project executes automatically and does not need to be added \think\app:: Run ();

2. Create the project name and the build.php file

Personal feeling thinkphp5.0 do a bad thing is that the above definition of the project folder needs to create its own, the reason, because the inside to put the project to create a configuration file build.php. But why does TP official not put build.php in the root directory? And then automatically generate the application folder? At this point I think TP3.2 do better than 5.0.

Now to discuss build.php, the official default bulid.php content is as follows, now to discuss

return [  //Generate run-time directory  ' __dir__ ' = [' Runtime/cache ', ' runtime/log ', ' runtime/temp ', ' runtime/template '],  ' __file__ ' = [' common.php '],  //define the automatic generation of the Index module  ' index ' and  [    ' __file__ '  and ' = ' Common.php '],    ' __dir__ '  = [' behavior ', ' controller ', ' model ', ' view '],    ' controller ' = [' Index ', ' Test ', ' usertype ', '    model '   = [],    ' view '    = [' Index/index '],  ],  //... Other more module definitions];

You can define the files and directories that need to be automatically generated for each module, as well as the MVC class.

__DIR__ indicates the build directory (multi-level directory support)
__FILE__ represents a makefile (does not define a default build config.php file)
Controller represents the generation of controller classes
Model indicates the generation of model classes
View to generate HTML files (subdirectories supported)

Automatically generated with App_path as the starting directory, __dir__ and __file__ represent the need to automatically create directories and files, others are automatically generated for the module.

The module is automatically generated with App_path. ' Module name/' as the starting directory.

Finally, you can run the index.php file directly.

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

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.