Download ThinkPHP 3.1.3 The file structure after decompression of the framework package:
├─ Common Framework public file directory
├─ Conf Framework configuration file directory
├─ Extend framework extension directory
├─ Lang framework system language directory
├─ Lib system core base class library directory
│ ├─ Behavior built-in behavior class library
│ ├─ Core Class library package
│ ├─ Driver built-in driver class library package
│ │ ├─ Cache built-in cache driver
│ │ ├─ Db built-in database driver
│ │ ├─ TagLib built-in tag driver
│ ├─ Template built-in template engine driver
├─ Tpl system template directory
├─ ThinkPHP.php framework entry file
New project entry file index.php
<?php require './ThinkPHP/ThinkPHP.php';
Access the project in the browser, the page displays:
At this time, the files under the project directory app have changed. Except for the entry file index.php and the framework package, all other files have changed. It is automatically generated:
The functions of each folder:
├─ Common Project public file directory
├─ Conf Project configuration directory
├─ Lang Project language package directory
├─ Lib Project class library directory
│ ├─ Action Action class library directory
│ ├─ Behavior Behavior class library directory
│ ├─ Model model Class library directory
│ ├─ Widget Widget class library directory
├─ Runtime Project runtime directory
│ ├─ Cache Template cache directory
│ ├─ Data Data cache directory
│ ├─ Logs Log file directory
│ ├─ Temp Temporary cache directory
├─ ThinkPHP Framework directory
├─ Tpl Project template directory
├─ index.php Project entry file
The entry file index.php in this method is stored in the project directory. You can also move the entry file outside the app directory and modify the entry file index.php:
<?php //定义项目名称 define('APP_NAME', 'Application'); // 定义项目路径 define('APP_PATH', './Application/'); //加载框架入口文件 require './ThinkPHP/ThinkPHP.php';
Directory structure:
There are two project deployment methods, one It is application deployment. Each project corresponds to an entry file. For example, the front-end entry file corresponds to index.php, and the back-end entry file corresponds to admin.php. This kind of project deployment is the recommended method of ThinkPHP;
Front-end entry file:
<?php define('APP_NAME', 'Home'); define('APP_PATH', './Home/'); require './ThinkPHP/ThinkPHP.php';
Back-end entry file:
<?php define('APP_NAME', 'Admin'); define('APP_PATH', './Admin/'); require './ThinkPHP/ThinkPHP.php';
The other is module group deployment, which maps all applications to one entry file, and the project template file is still placed Go to the Tpl directory of the project and just put the externally called resource files, including images JS and Css, under the public directory Public of the website, and store them in the Images, Js and Css subdirectories. If possible, you can even put these The resource file is placed separately for remote calling by an external server and optimized.
Module grouping needs to configure APP_NAME and APP_PATH;
Create the project directory App in the WEB root directory, and copy the framework package ThinkPHP to the same level directory, and at the same time At the same level, create the public resource directory Public for all projects, the public upload directory Uploads for all projects, and the entry file index.php:
The entry file index.php:
<?php define('APP_NAME', 'App'); define('APP_PATH', './App/'); //开启debug,不加载缓存文件 define('APP_DEBUG', true); require './ThinkPHP/ThinkPHP.php';
Access index.php through url. After initializing the project environment, the automatically generated directory under the App directory:
Then in the App/Conf/config.php configuration file, configure Grouping options:
<?php return array( //'配置项'=>'配置值' 'APP_GROUP_LIST' => 'Admin,Home', 'DEFAULT_GROUP' => 'Home', );
If you access the index.php entry file at this time, ThinkPHP will report an error:
Because module grouping is enabled in the public configuration file, However, the corresponding group directory has not been created, and the respective configuration files of the Admin and Home groups need to be manually created: Create the Admin and Home directories under the Conf directory.
Then create config.php configuration files in the directories respectively; the App/Lib/Action directory also needs to create the Admin and Home directories, and then move the default created IndexAction.class.php file to App/Lib/Action /Home directory, no error will be reported when accessing the entry file, and the project deployment is successful:
If you hide the entry file, the URL addresses of the two will look almost the same:
Recommended tutorial: "TP5 》
The above is the detailed content of thinkphp3.1 project development and deployment. For more information, please follow other related articles on the PHP Chinese website!