With excitement opened the thinkphp document, opening the first PHP framework to learn.
Download
Thinkphp Latest version available on the official website (http://thinkphp.cn/down/framework.html)
or github (https://github.com/liu21st/thinkphp/downloads) download.
Extract the downloaded compressed files to your web directory (or any directory)
It is recommended to download the full version, which can be re-configured during a lot of inexplicable trouble
Entry file
The contents of the official website are attached below
Before you start, you need a Web server and PHP runtime environment, and if you haven't, we recommend using the Integrated development environment Wampserver (a development kit that integrates Apache, PHP, and MySQL, and supports multiple PHP versions, MySQL version and Apache version of the switch) to use thinkphp for local development and testing.
Next we create an app subdirectory below the Web root directory (the app is our project name), then create a index.php file underneath the directory and add a simple line of code:
Require '/thinkphp framework directory/thinkphp.php ';
In fact, this index.php do not need to create their own, in the download package is already there.
Single Project
We can access the project directly through http://localhost/.
Multi-item
If you want to create multiple projects, you can also Web Create multiple subdirectories under the root directory to deploy multiple projects. Each project directory contains a portal file.
Create Project1 folder
Create and open a portal file ( index.php )
Add the following code
<?php
define (' App_debug ', true);// turn on debug mode
Require ('.. /thinkphp/thinkphp.php ');
?>
Open in Browser http://localhost/project1/ , you can see thinkphp 's Welcome page.
thinkphp Running Process
What happens when the browser accesses the portal file? What is the implementation process of think?
(1) The first step: Introduce the thinkphp.php under the frame
The thinkphp.php file, which defines constants app_name and Think_path (uppercase), and introduces runtime.php
(2) Step two, load the common/runtime.php file under the frame
- Once again, some constants are defined, see the source code in detail;
- Create the project directory structure, created by the Build_app_dir () method;
- If App_dubug is set to False, the core load file is compiled. Otherwise, delete the compiled file, which is the ~runtime.php file under the project;
- Call the lib/core/think.class.php file under frame thinkphp and execute the Portal Think::start ().
(3) Step three, execute the lib/core/think.class.php start () method under the framework thinkphp
- Take the second step and start executing the portal file Think::start (). Includes declaring error handling handle, exception handling handle, and declaring the class's automatic loading mechanism;
- Think::buildapp (); Initialize the app to run, that is, Project precompilation, load the project's various configuration files, about 10 files around.
- After loading the configuration file, execute App::run
(4) Fourth step, run method under lib/core/app.class.php under the framework of execution
- Execute the App init () static method: Parse the URL to see which controller is called.
- Execute the Exec static method under the app: Instantiate the module and execute the action corresponding method based on the calculated model and method. This example finds the item under the Lib/action directory under the IndexAction.class.php, and executes the index () method.
After so many steps, we finally saw the thinkphp welcome page displayed on the browser.
Site sharing
Website:
http://www.thinkphp.cn/
Api:
http://doc.thinkphp.cn/
Forum:
http://www.ithinkphp.com/
thinkphp Study Notes--environment construction