


How to automatically generate modules and directories in Thinkphp5.0
This article mainly introduces the method of automatically generating modules and directories in Thinkphp5.0, and briefly analyzes the structure, directory, creation and operation methods of Thinkphp5.0. Friends in need can refer to the examples of this article
Describes how Thinkphp5.0 automatically generates modules and directories. I share it with you for your reference. The details are as follows:
Thinkphp5.0 has been released for some time. It is said that the performance has been greatly improved. According to the official words, ThinkPHP5.0 version is a subversive and reconstructed version. , adopts a new architectural idea, introduces many new PHP features, optimizes the core, reduces dependencies, achieves true lazy loading, and makes a lot of optimizations for API development. It’s time to download a copy and study it. Today we mainly talk about its automatic creation of modules and directories.
Thinkphp5.0 automatically generates modules compared to ThinkPHP3.2. There are indeed big changes.
Once again, we mainly discuss the Thinkphp5.0 generation module.
Preparation work
First download ThinkPHP5.0 from the official website. After downloading, the file structure is as follows:
Only keep the thinkphp directory and delete all other directories and files (you can move them to other places first for subsequent use)
Start generating the project directory now
Creating a directory seems simple with thinkphp3.2, but thinkphp5.0 is more flexible. I can't help but think that good people make complex things simple; mediocrity makes simple things complicated; fools make simple things simpler and complex things more complicated.
1. Create the entry file index.php. Although the official emphasizes that the location of the entry file can be placed at will, but for the convenience of learning, it is still placed in the root directory
// 应用入口文件 define('APP_PATH', 'application/'); // 定义项目路径,和之前3.2版本没有区别 define('APP_AUTO_BUILD',true); //开启自动生成 define('APP_DEBUG', true);// 开启调试模式 define('MODULE','module'); // 加载框架引导文件 require 'thinkphp/start.php'; // 执行应用 \think\App::run();
In fact, I personally think that TP Why didn't the official place the execution of the program\think\App::run(); in the start.php directory? Finally, it was discovered that TP5.0 introduced a define('APP_AUTO_RUN', true); constant. If the constants are defined on the index.php page, the project will be executed automatically. There is no need to add \think\App::run();
2. Create the project name and build.php file
Personally, I feel that one thing that thinkphp5.0 does poorly is that the project folder defined above needs to be created by yourself. The reason is that the project creation configuration file build.php must be placed in it. But why doesn’t TP official place build.php in the root directory? Then automatically generate the application folder? At this point, I think TP3.2 is better than 5.0.
Now let’s discuss build.php. The official default bulid.php content is as follows. Now let’s discuss it.
return [ // 生成运行时目录 '__dir__' => ['runtime/cache', 'runtime/log', 'runtime/temp', 'runtime/template'], '__file__' => ['common.php'], // 定义index模块的自动生成 'index' => [ '__file__' => ['common.php'], '__dir__' => ['behavior', 'controller', 'model', 'view'], 'controller' => ['Index', 'Test', 'UserType'], 'model' => [], 'view' => ['index/index'], ], // 。。。 其他更多的模块定义 ];
You can define files and directories that need to be automatically generated for each module, as well as MVC kind.
__dir__ represents the generated directory (supports multi-level directories)
__file__ represents the generated file (the config.php file will be generated by default if not defined)
controller represents the generated controller class
model represents Generate model class
view means generating html files (supports subdirectories)
Automatically generate APP_PATH as the starting directory, __dir__ and __file__ mean that directories and files need to be automatically created, and others mean Automatically generated for modules.
The automatic generation of modules takes APP_PATH.'Module name/' as the starting directory.
Finally, run the index.php file directly.
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
ThinkPHP implements cross-module calling
ThinkPHP template replacement and system constants and application examples
The above is the detailed content of How to automatically generate modules and directories in Thinkphp5.0. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
![WLAN expansion module has stopped [fix]](https://img.php.cn/upload/article/000/465/014/170832352052603.gif?x-oss-process=image/resize,m_fill,h_207,w_330)
If there is a problem with the WLAN expansion module on your Windows computer, it may cause you to be disconnected from the Internet. This situation is often frustrating, but fortunately, this article provides some simple suggestions that can help you solve this problem and get your wireless connection working properly again. Fix WLAN Extensibility Module Has Stopped If the WLAN Extensibility Module has stopped working on your Windows computer, follow these suggestions to fix it: Run the Network and Internet Troubleshooter to disable and re-enable wireless network connections Restart the WLAN Autoconfiguration Service Modify Power Options Modify Advanced Power Settings Reinstall Network Adapter Driver Run Some Network Commands Now, let’s look at it in detail

This article details methods to resolve event ID10000, which indicates that the Wireless LAN expansion module cannot start. This error may appear in the event log of Windows 11/10 PC. The WLAN extensibility module is a component of Windows that allows independent hardware vendors (IHVs) and independent software vendors (ISVs) to provide users with customized wireless network features and functionality. It extends the capabilities of native Windows network components by adding Windows default functionality. The WLAN extensibility module is started as part of initialization when the operating system loads network components. If the Wireless LAN Expansion Module encounters a problem and cannot start, you may see an error message in the event viewer log.

The glob() function in PHP is used to find files or directories and is a powerful file operation function. It can return the path of a file or directory based on a specified pattern match. The syntax of the glob() function is as follows: glob(pattern, flags) where pattern represents the pattern string to be matched, which can be a wildcard expression, such as *.txt (matching files ending with .txt), or a specific file path. flags is an optional parameter used to control the function

Use the path/filepath.Dir function to obtain the directory part of the file path. In our daily development process, file path processing is often involved. Sometimes, we need to get the directory part of the file path, that is, the path to the folder where the file is located. In the Go language, you can use the Dir function provided by the path/filepath package to implement this function. The signature of the Dir function is as follows: funcDir(pathstring)string The Dir function receives a word

WPS is a powerful office software that can help us complete various office tasks efficiently. Among them, automatically generating table of contents page numbers is a very practical function. It can greatly improve the work efficiency of users, so the editor of this website will bring you this article to introduce in detail how to use WPS to automatically generate directory page numbers. I hope it can help everyone in need. How to automatically generate table of contents page numbers for a wps directory. First, open the wps group document, enter the content of the table of contents to be generated in the blank space, and then select the styles of title 1, title 2, and title 3 in the start menu bar. 2. Then after setting it up, we click the [Reference] function. After clicking, in the reference toolbar, here we click [Directory]; 3. Finally click

Select the style of the catalog in Word, and it will be automatically generated after the operation is completed. Analysis 1. Go to Word on your computer and click to import. 2After entering, click on the file directory. 3 Then select the style of the directory. 4. After the operation is completed, you can see that the file directory is automatically generated. Supplement: The table of contents of the summary/notes article is automatically generated, including first-level headings, second-level headings and third-level headings, usually no more than third-level headings.

The mobile version of WeChat Reading App is a very good reading software. This software provides a lot of books. You can read them anytime, anywhere with just one click to search and read them online. All of them are officially authorized and different types of books are neatly arranged. Sort and enjoy a comfortable and relaxing reading atmosphere. Switch the reading modes of different scenarios, update the latest book chapters continuously every day, support online login from multiple devices, and batch download to the bookshelf. You can read it with or without the Internet, so that everyone can discover more knowledge from it. Now the editor details it online Promote the method of viewing the catalog for WeChat reading partners. 1. Open the book you want to view the catalog and click in the middle of the book. 2. Click the three lines icon in the lower left corner. 3. In the pop-up window, view the book catalog

The working principle of Ansible can be understood from the above figure: the management end supports three methods of local, ssh, and zeromq to connect to the managed end. The default is to use the ssh-based connection. This part corresponds to the connection module in the above architecture diagram; you can press the application type HostInventory (host list) classification is carried out in other ways. The management node implements corresponding operations through various modules. A single module and batch execution of a single command can be called ad-hoc; the management node can implement a collection of multiple tasks through playbooks. Implement a type of functions, such as installation and deployment of web services, batch backup of database servers, etc. We can simply understand playbooks as, the system passes
