Home PHP Framework ThinkPHP thinkphp3.1 project development and deployment

thinkphp3.1 project development and deployment

May 28, 2020 am 09:36 AM
thinkphp

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;;

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;;

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;;

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;;

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;;

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;,
);

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!

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Peak: How To Revive Players
1 months ago By DDD
PEAK How to Emote
4 weeks ago By Jack chen

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

Development suggestions: How to use the ThinkPHP framework for API development Development suggestions: How to use the ThinkPHP framework for API development Nov 22, 2023 pm 05:18 PM

Development suggestions: How to use the ThinkPHP framework for API development. With the continuous development of the Internet, the importance of API (Application Programming Interface) has become increasingly prominent. API is a bridge for communication between different applications. It can realize data sharing, function calling and other operations, and provides developers with a relatively simple and fast development method. As an excellent PHP development framework, the ThinkPHP framework is efficient, scalable and easy to use.

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

See all articles