Home > PHP Framework > ThinkPHP > body text

thinkphp3.1 project development and deployment

Release: 2020-05-28 09:36:03
forward
3936 people have browsed it

thinkphp3.1 project development and deployment

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 &#39;./ThinkPHP/ThinkPHP.php&#39;;
Copy after login

Access the project in the browser, the page displays:

thinkphp3.1 project development and deployment

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:

thinkphp3.1 project development and deployment

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(&#39;APP_NAME&#39;, &#39;Application&#39;);
// 定义项目路径
define(&#39;APP_PATH&#39;, &#39;./Application/&#39;);
//加载框架入口文件
require &#39;./ThinkPHP/ThinkPHP.php&#39;;
Copy after login

Directory structure:

thinkphp3.1 project development and deployment
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;

thinkphp3.1 project development and deployment

Front-end entry file:

<?php
define(&#39;APP_NAME&#39;, &#39;Home&#39;);

define(&#39;APP_PATH&#39;, &#39;./Home/&#39;);

require &#39;./ThinkPHP/ThinkPHP.php&#39;;
Copy after login

Back-end entry file:

<?php
define(&#39;APP_NAME&#39;, &#39;Admin&#39;);

define(&#39;APP_PATH&#39;, &#39;./Admin/&#39;);

require &#39;./ThinkPHP/ThinkPHP.php&#39;;
Copy after login

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.

thinkphp3.1 project development and deployment

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:

thinkphp3.1 project development and deployment

The entry file index.php:

<?php
define(&#39;APP_NAME&#39;, &#39;App&#39;);

define(&#39;APP_PATH&#39;, &#39;./App/&#39;);

//开启debug,不加载缓存文件
define(&#39;APP_DEBUG&#39;, true);

require &#39;./ThinkPHP/ThinkPHP.php&#39;;
Copy after login

Access index.php through url. After initializing the project environment, the automatically generated directory under the App directory:

thinkphp3.1 project development and deployment

Then in the App/Conf/config.php configuration file, configure Grouping options:

<?php
return array(
    //&#39;配置项&#39;=>&#39;配置值&#39;
    &#39;APP_GROUP_LIST&#39; => &#39;Admin,Home&#39;,
    &#39;DEFAULT_GROUP&#39; => &#39;Home&#39;,
);
Copy after login

If you access the index.php entry file at this time, ThinkPHP will report an error:

thinkphp3.1 project development and deployment

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:

thinkphp3.1 project development and deployment

thinkphp3.1 project development and deployment

If you hide the entry file, the URL addresses of the two will look almost the same:

1thinkphp3.1 project development and deployment

1thinkphp3.1 project development and deployment

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!

Related labels:
source:jianshu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template