ThinkPHP5 installation and use/tp5 Quick Start, thinkphp5tp5

Source: Internet
Author: User
Tags php database traits

ThinkPHP5 installation and use/tp5 Quick Start, thinkphp5tp5

Click to go to the video tutorial


This notebook is based on thinkPHP5.0.1. Because ThinkPHP5 is updated quickly in Small versions, the difference between 5.0.0 and 5.0.1 is still a little large. For example, some functions of 5.0.0 will be discarded or changed in later versions. Therefore, when reading this notebook, make sure that the version of ThinkPHP you are using is 5.0.1. The recorded process is not a general process of framework learning, it is written for the purpose of quickly mastering and using frameworks by experienced programmers. It will begin from how to quickly start using a framework to the in-depth description of the framework.

ThinkPHP5 framework Description

ThinkPHP5 is a very popular framework in China, although the project release time is not long. ThinkPHP should start with ThinkPHP3.2.3. ThinkPHP3.2.3 is a very popular php framework and a very simple framework. Over time, ThinkPHP is like a popular PHP framework (Laravel, yii2 and so on) are constantly admired for their design ideas, and ThinkPHP3.2.3's shortcomings are also very obvious. The birth of ThinkPHP5 completely changed the design ideas of version 3.2.3, closer to Yii2 and Laravel, it also shows the determination of the domestic framework to develop towards excellent products.
Some new PHP features are introduced in ThinkPHP5, such as trait. ThinkPHP supports responses to xml or json data. For ajax requests, data is processed as json and then returned, and Resource Controller, which reflects the convenience of api development.

ThinkPHP5 framework installation configuration server running framework configuration Virtual Host:

Configure the server in the virtual host file of Nginx vhosts. Configure root as the public directory of the project. Configure server_name and map the domain name to the local hosts file.

server {   listen 80;  server_name;  access_log /data/wwwlogs/local.tp5.com_nginx.log combined;  index index.html index.htm index.php;  root /data/wwwroot/edutp5/public;  if (!-e $request_filename) {          rewrite  ^(.*)$  /index.php?s=/$1  last;          break;     }   location ~ \.php {    #fastcgi_pass remote_php_ip:9000;    fastcgi_pass unix:/dev/shm/php-cgi.sock;    fastcgi_index index.php;    include fastcgi_params;    set $real_script_name $fastcgi_script_name;    if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {      set $real_script_name $1;      #set $path_info $2;    }    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;    fastcgi_param SCRIPT_NAME $real_script_name;    #fastcgi_param PATH_INFO $path_info;  }}

The if clause determines that it is a URL rewrite rule. To save index. php In the URL. Restart the Nginx Service After configuring Nginx.

Add URL ing in hosts:

Open the hosts file in the system, add the following line in it, and save

Runtime framework:

Enter in the browser to access the framework content.

View the Directory and find the MVC

Edutp5 Application Deployment directory
‑Application application directory (configurable)
│ Catalog-common public Module Directory (Changeable)
│ Catalog-index Module Directory (Changeable)
│ ├ ── Config. php module configuration file
│ Functions-common. php module function File
│ ─-Controller directory
│ ├-Model directory
│ Preview-view directory
│ ─ ──... More class library Directories
│ ─ ── Command. php command Line tool configuration file
│ Common── common. php application public (function) File
│ ├ ── Config. php application (public) configuration file
│ ├ ── Database. php database Configuration File
│ ├ ── Tags. php app behavior extension definition file
│ Route-route. php route configuration file
Extended class library directory (customizable)
Deployment-public WEB deployment directory (external access directory)
│ ├ ── Static resource storage directory (css, js, image)
│ Choose-index. php app portal File
│ ├ ── Router. php quick test file
│ ─ ──. Htaccess is used to rewrite apache
Runtime-runtime directory of the runtime application (writable and configurable)
Category-vendor third-party class library directory (Composer)
├ ── Thinkphp framework system directory
│ ├ ── Lang Language Pack directory
│ ├-Library Framework core class library directory
│ ├ ── Think Think class library package directory
│ └ ── Traits system Traits directory
│ ├ ── Tpl system template directory
│ ─ ──. Htaccess is used to rewrite apache
│ ─ ──. Travis. yml CI definition file
│ ├-Base. php basic definition file
│ Define-composer. json composer definition file
│ ├-Console. php console portal File
│ ├-Convention. php convention configuration file
│ Helper-helper. php helper function file (optional)
│ ├─LICENSE.txt authorization instruction file
│ ├ ── Phpunit. xml unit test configuration file
│ ‑Readme. md README file
│ Restart-start. php framework boot file
├ ── Build. php automatically generates a definition file (reference)
Define-composer. json composer definition file
License license license.txt authorization instruction file
├ ── README. md README file
Cmd── think command line entry file

The results of this directory are copied from the official thinkphp5 documents. The important directories to be understood are marked red directories and files.

Note that the application is the application directory. Each of our applications may consist of multiple modules. For example, the index in this project is a module. Each module contains the complete configuration and mvc structure. In config. php, the configuration file type can be customized to flexibly use the configuration in json or xml format. Controller, model, and view are controller directories, model directories, and view directories respectively.

Project Access

URL structure explanation:
This URL indicates accessing the test operation in the index controller of the index module. In this example, we know the general URL format. Here, index. php can be omitted. If the Nginx configuration is configured according to my notes, the URL Rewrite Rules have been written, and no index. php is added during access.

Can be changed to:

The corresponding file is the test operation in edutp5/index/Index. php. If you create a new controller, follow the http access method: // your basic URL address/Module name/controller/operation. Of course, the definition of routing rules and the use of routing may vary depending on the method of request after the route is defined.

Step on
View comments

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.