Function and definition of file entry
File entry definition
6.0 The default application entry file is located in public/index.php, by default The content is as follows:
// [ 应用入口文件 ] namespace think; require __DIR__ . '/../vendor/autoload.php'; // 执行HTTP应用并响应 $http = (new App())->make('http'); $response = $http->run(); $response->send(); $http->end($response);
If you have no special customization requirements, there is no need to make any changes to the entry file.
The entry file location is designed to make application deployment safer. Please try to follow the public directory as the only web-accessible directory. Other files can be placed in non-WEB-accessible directories.
Console entry file
In addition to the application entry file, the system also provides a console entry file, located in think in the project root directory (note that this file does not have any suffix).
The file code is as follows:
#!/usr/bin/env php <?php namespace think; // 加载基础文件 require __DIR__ . '/vendor/autoload.php'; // 应用初始化 (new App())->console->run();
The console entry file is used to execute console commands, for example:
php think version
The system has built-in some commonly used console commands. If you When additional extensions are installed, corresponding console commands will also be added, all of which are executed through this entry file.
If there are class library directories such as controller, model, and view directly under the app directory, it is single application mode (default mode). If an application subdirectory is created under the app directory, it will automatically become multi-application mode. .
The directory structure differences between single application and multiple applications are as follows (mainly in the app directory).
Single application mode
├─app application directory
│ ├─controller Controller directory
│ ├─model Model directory
│ ├ ─ View View Catalog
│ └ ─ ... More types of library directory
# │
## ├ ─ PUBLIC Web directory (external access directory)
│ ├─index.php │ Entry file│ ├─router.php Quick test file│ └─.htaccess Rewrite for apache│ ├─config Application configuration directory├─route Route definition directory├─runtime outps out out outps out outps out field field field field field field field field field best to to be so so?
├─app application directory
│ ├─index
##’│ │ v─VIEW View Catalog
# │ │ ├ ─CONFIG Configuration Catalog (Preferred)
│ │ └ ─ ... More types of library directory
│ ├─admin Backend application
│ │ ├─controller Controller directory
│ │ ├─model Model directory
│ │ ├─view View directory
│ │ ├─config Configuration directory (Priority)
│ │ └ ─ ... More types of library directory
│
─ Public web directory (external access directory)
Use Rewrite of apache
│
├─config Application configuration directory
│ ├─index Index application configuration
│ └─admin Admin application configuration
# │
# ─ Route route definition directory
# ─ ─index index application route definition directory
# ─ a └ a └ └ └ ─Admin admin.
##│├─runtime Runtime directory│ ├─index index application runtime directory│ └─admin admin application runtime directoryAs can be seen from the directory structure, each application remains relatively independent, and each application has a corresponding entry file. The application can also maintain controller groups through multi-level controllers. When multiple applications use different entries, the content of each entry file is the same. The default entry file name (without suffix) is the application name. If your entry file name is inconsistent with the application, for example For your backend admin application, the entry file name uses think.php, then the entry file needs to be changed to:// [ 应用入口文件 ] namespace think; require __DIR__ . '/../vendor/autoload.php'; // 执行HTTP应用并响应 $http = (new App())->make('http'); $response = $http->name('admin')->run(); $response->send(); $http->end($response);Single application and multi-application modes will affect the values of some system paths. In order to better understand this manual content, you may need to understand the locations represented by the following system paths.
Directory location | Directory description | Getting method |
---|---|---|
Root directory | The directory where the project is located is automatically obtained by default and can be passed in when the entry file instantiates the App class. | App::getRootPath() |
Basic directory | app directory under the root directory | App::getBasePath() |
Application directory | The directory where the current application is located, if it is single application mode Same as the basic directory. If it is multi-application mode, it is app /application subdirectory | App::getAppPath() |
Configuration Directory | config Directory under the root directory | App::getConfigPath() |
Runtime directory | The directory when the framework is runtime. Single application mode is the runtime directory of the root directory. Multi-application mode is runtime /application subdirectory#. | ##App::getRuntimePath()
|
Framework core class library | thinkDirectory | App::getThinkPath()
|