thinkphp automatically generates directory structure

thinkPHP5 comes with a default auto-generated rule file

[php]  view plain copy  
  1. <?php  
  2. return [  
  3.     // Generate application public files  
  4.     '__file__' => ['common.php''config.php''database.php'],  
  5.   
  6.     // Define the automatic generation of the demo module (generated according to the actual defined file name)  
  7.     'demo'     => [  
  8.         '__file__'    => [ 'common.php' ],  //The generated file, if not defined, the config.php file will be generated by default  
  9.         '__dir__'     => [ 'behavior' 'controller' 'model' 'view' ],  //Generate directory (support multi-level directory)  
  10.         'controller'  => [ 'Index' 'Test' 'UserType' ],   //Generate controller class  
  11.         'model'       => [ 'User' 'UserType' ],   //Generate model class  
  12.         'view'        => [ 'index/index' ],  //Generate html file, support subdirectories  
  13.     ],  
  14.     // other more module definitions  
  15. ];  

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

[php]  view plain copy  
  1. 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:

  1. <?php  
  2.   
  3. // define the application directory  
  4. define('APP_PATH', __DIR__ . '/../application/');  
  5. // Load the framework bootstrap file  
  6. require __DIR__ . '/../thinkphp/start.php';  
  7. // Read the auto-generated definition file  
  8. $build = include'./../build.php';   
  9. // run auto build  
  10. \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]  view plain copy  
  1. <?php  
  2.   
  3. // define the application directory  
  4. define('APP_PATH', __DIR__ . '/../application/');  
  5. // Load the framework bootstrap file  
  6. require __DIR__ . '/../thinkphp/start.php';  
  7. // Automatically generate admin module  
  8. \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




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325994136&siteId=291194637