ThinkPHP introduction:

  • ThinkPHP was created to simplify enterprise application development and agile WEB application development. It was first born at the beginning of 2006, and officially changed its name to ThinkPHP on New Year’s Day 2007, and followed the release of Apache2 open source agreement. ThinkPHP has been designed for simplicity since its inception, focusing on ease of use while maintaining excellent performance and simple code. With the active participation of the community team, it has been constantly optimized and improved in terms of ease of use and scalability. ThinkPHP is a fast, compatible, and simple, lightweight, homegrown PHP development framework.

1. MVC framework

  • Model (M) : The Model definition is done by the Model class. The Model class is located in the LibModel directory under the project directory.
  • Controller (C) : Both the application controller (core controller) and the Action controller assume the role of controller. The difference lies in that the Action controller completes the business process, while the application controller (App class) is responsible for scheduling control. The Action controller is located in the LibAction directory under the project directory.
  • Attempt (V) : The template implementation is framework-independent, 100% detached, and can be previewed and crafted independently. The template directory is located in the Tpl directory under the project directory.
  • Website: http://www.thinkphp.cn

First, build projects with ThinkPHP

  • Modify the http.conf file (/private/etc/apache2)

Open the file (remove comments) : Include/private/etc/apache2 / extra/HTTPD - vhosts. Conf

Open file :(if not added) LoadModule rewrite_module modules/mod_rewrite.so

Change AllowOverride None to AllowOverride All

  • Open the HTTPD – vhosts. Conf file, add the following content: (/ private/etc/apache2 / extra)

  <VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents/tp/public/"
    ServerName tptest.com
    ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
     <Directory "/Library/WebServer/Documents/tp/public">
    	Options FollowSymLinks Multiviews
    	MultiviewsMatch Any
   	AllowOverride All
        Require all granted
      </Directory>
   </VirtualHost>
Copy the code
  • Modifying the hosts file (/private/etc)

Added: 127.0.0.1 tptest.com

  • Restart the apachectl

Restart: sudo apachectl restart

Start: sudo apachectl start

  • In a browser: tptest.com

Physical access is: http://tptest.com/index.php/index/index/index

Is equivalent to: http://tptest.com/index.php?m=index&c=index&a=index

Second, the directory architecture of TP5 framework

  • The whole directory

  • Index Indicates the directory in the module


3. Display the corresponding view

  • Method 1: Create your own View object without inheriting Controller
  • $this->fetch(); operation


Create a view

5. Create a controller

Set default controllers and actions