ThinkPHP learning notes-environment building and thinkphp handwriting Building

Source: Internet
Author: User

ThinkPHP learning notes-environment building and thinkphp handwriting Building

With excitement, I opened the thinkPHP documentation and started the first php framework learning.

Download

The latest ThinkPHP version can be found on the official website (http://thinkphp.cn/down/framework.html)

Or download it from Github (https://github.com/liu21st/thinkphp/downloads.
Decompress the downloaded compressed file to your WEB directory (or any directory)

We recommend that you download the full version, which saves you a lot of trouble during configuration.

Portal File

The content of the official website is attached below

Before you start, you need a Web server and PHP runtime environment, we recommend that you use the integrated development environment WAMPServer (a development kit that integrates Apache, PHP, and MySQL, and supports switching between multiple PHP versions, MySQL versions, and Apache versions) to use ThinkPHP for local development and testing.
Next, create an app subdirectory under the WEB root directory (this app is our project name), create an index. php file under the directory, and add a simple line of code:

Require '/ThinkPHP framework directory/ThinkPHP. php ';

In fact, this index. php does not need to be created by yourself. It already exists in the downloaded package.

Single Project

We can directly access the project through http: // localhost.

Multiple projects

If you want to create multiple projects, you can also create multiple subdirectories under the Web root directory to deploy multiple projects. Each project directory contains an entry file.

Create a project1 folder

Create and open the entry file (index. php)

Add the following code:

<? Php

Define ('app _ debug', true); // enable debugging mode

Require ('../ThinkPHP. php ');

?>

Open http: // localhost/project1/in the browser to see the thinkphp welcome page.

ThinkPHP running process

What happened when the browser accessed the entry file? What is the execution process of think?

(1) Step 1: Introduce thinkphp. php under the Framework

The thinkphp. php file defines the constant app_name and think_path (uppercase), and introduces runtime. php.

(2) Step 2: load the Common/runtime. php file under the Framework

  • Some constants are defined again. For details, see the source code;
  • Create a project directory structure, which is created by the build_app_dir () method;
  • If app_dubug is set to false, the core Load file is compiled. Otherwise, delete the compilation file, that is, ~ Runtime. php file;
  • Call the lib/core/Think. class. php file under the ThinkPHP framework --> execution entry Think: Start ().

(3) Step 3: Execute the start () method of lib/core/Think. class. php under the ThinkPHP framework.

  • Next, Start the Think: Start () file (). Including declaring the error handling handle and Exception Handling handle, and declaring the automatic loading mechanism of the class;
  • Think: buildApp (); // initialize the app to run, that is, project pre-compilation. There are about 10 configuration files for the add-on.
  • After the configuration file is loaded, run the app: run

(4) Step 4: Execute the run method under lib/core/App. class. php under the framework.

  • Execute the init () static method under the app: analyze the url to find the Controller to call.
  • Execute the exec static method in the app: instantiate the module based on the calculated model and method, and execute the corresponding action method. IndexAction. class. php under the lib/action directory of the project found in this instance, and execute the index () method.

 

After the above steps, we finally see the thinkphp welcome page displayed on the browser.

Website sharing

Official Website:

Http://www.thinkphp.cn/

API:

Http://doc.thinkphp.cn/

Forum:

Http://www.ithinkphp.com/

 

 


New users need to build a PHP environment to learn PHP?

You do not need to install the integration package, such as xampp, appserver, and phpnow.

What integrated development environment does thinkphp use for development? I am using eclipse, but the thinkphp method cannot be automatically located.

The method cannot be automatically located.
 

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: info-contact@alibabacloud.com 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.