thinkPHP5 comes with a default auto-generated rule file
- <?php
- return [
- // Generate application public files
- '__file__' => ['common.php', 'config.php', 'database.php'],
- // Define the automatic generation of the demo module (generated according to the actual defined file name)
- 'demo' => [
- '__file__' => [ 'common.php' ], //The generated file, if not defined, the config.php file will be generated by default
- '__dir__' => [ 'behavior' , 'controller' , 'model' , 'view' ], //Generate directory (support multi-level directory)
- 'controller' => [ 'Index' , 'Test' , 'UserType' ], //Generate controller class
- 'model' => [ 'User' , 'UserType' ], //Generate model class
- 'view' => [ 'index/index' ], //Generate html file, support subdirectories
- ],
- // other more module definitions
- ];
The automatic generation of the module takes APP_PATH.'module name/' as the starting directory
In the entry file index.php, tp5 has defined APP_PATH, that is, the starting directory is located in the applicaton folder
- define('APP_PATH', __DIR__ . '/../application/');
And the default Index access controller file of the module is automatically generated to display the page of the frame
2. Automatically generate directory operations
In the entry file index.php, you can directly call the method of the \think\ class for automatic generation:
- <?php
- // define the application directory
- define('APP_PATH', __DIR__ . '/../application/');
- // Load the framework bootstrap file
- require __DIR__ . '/../thinkphp/start.php';
- // Read the auto-generated definition file
- $build = include'./../build.php';
- // run auto build
- \think\Build::run($build);
When running tp5 , there will be an additional demo folder under the open application file : ( demo) The structure can be defined,
Call the run operation of think/Build
You can also generate modules directly using the default directory
- <?php
- // define the application directory
- define('APP_PATH', __DIR__ . '/../application/');
- // Load the framework bootstrap file
- require __DIR__ . '/../thinkphp/start.php';
- // Automatically generate admin module
- \think\Build::module('admin');
Call the module operation of think/Build
3. Access to custom modules
The default access address http://localhost/tp5/public/ accesses index.php, the application entry folder application is defined in index.php, and the default access is the index class under the Index controller under the index module
http://localhost/tp5/public/index.php/index/index/index
Therefore, if you access the index class of the Index controller of the demo and admin modules created above, the access address should be:
http://localhost/tp5/public/index.php/demo/index/index
http://localhost/tp5/public/index.php/admin/index/index