: This article mainly introduces Thinkphp entry 1 (45). If you are interested in the PHP Tutorial, refer to it. What is a framework?
It is a collection of code that can include variables, constants, functions, classes, and so on. These codes are closely related to each other and cooperate with each other. There are also Design Patterns: MVC, Singleton, and factory.
Why learning frameworks?
1. all our energy can be concentrated at the business level, saving about 60% of the workload.
2. this function helps us quickly, stably, and efficiently build a program system.
3. the system's robustness, maintenance, flexibility, and adaptability to customer needs have been greatly enhanced
Mature framework
1. zendFramework: the official framework. Weight
2 Yii: OOP weight
3 cakephp: medium volume
4 symfony weight
5 CodeIgniter lightweight
6 ThinkPHP lightweight
7. there are still many unknown frameworks.
When to use the framework
1. there are a lot of program Project code and complicated functions.
2. the project time is very short.
Application Catalog description
Project Application
Description of The boke application directory (the directory automatically created after the program runs)
Application entry file:
MVC design pattern
Entry program file
C: controller
V: view
M: model
Compile cache files ~ Runtime. php
The tp Framework compiles many files to be loaded by the system into one file for performance consideration. This file is ~ Runtime. php, which saves a lot of overhead for opening and disabling files.
Code Tracing:
1. index. php entry
2. ThinkPHP. php
3. ThinkPHP/Common/runtime. php
4. Think: Start (); ThinkPHP/Lib/Core/Think. class. php
L Think: buildApp ()
L App: run () ThinkPHP/Lib/Core/App. class. php
5 App: run ()
L App: exec ();
The reflection mechanism is used to instantiate the controller object and call the corresponding method.
Note:
Our css, js, img images and other website resources need to be accessed separately.
Web requests through routing
Template creation:
Controller call Template display content:
- Call a specific template through display ()
- Create a template file under the Tpl Directory
- Modify the css and img Image directory addresses of the template file and the css Image address
- Create css, img, and js constants in the index. php file for the template.
Current Portal file:
Summary:
- Create an application using the tp framework and create an entry File (go/index. php)
- Create multiple controllers, refer to index controller. All controllers inherit the Action parent class.
- Use the controller to call the View template display ()
- Display template content
Create a template under Tpl
Modify the directory address of css and img
The above introduces Thinkphp entry 1 (45), including some content, and hopes to help those who are interested in PHP tutorials.