thinkphp Primer One (45)
What is a framework?
is a collection of code that can have variables, constants, functions, classes, and so on. These codes are closely related to each other and have a cooperative relationship. There are also design patterns: MVC, Singleton, Factory, and so on.
Why study the framework?
1. All our energies can be focused on the business level, can save about 60% of the workload
2. This function can help us to set up the program system quickly, stably and efficiently.
3. Robust, maintenance, flexible and adaptable to customer needs
Mature Framework
1 Zendframework: Official framework. Weight
2 Yii:oop Weight
3 cakephp: Medium volume
4 Symfony Weight
5 CodeIgniter Light Weight
6 thinkphp Light Weight
7 and so on, there are many unknown frameworks.
When to use frames
1. The program project code is very many, the function is very complex.
2. Project time is very tight.
Application Directory Description
Project Application
Boke application Directory Description (the directory created automatically after the program is run)
Application's entry file:
MVC design Pattern
Entry Program Files
C: Controller Controllers
V: Views View
M: Model
Compiling cache files ~runtime.php
is the TP framework for performance considerations, the system needs to load a lot of files are compiled into a file inside, this file is ~runtime.php, so that the system saves a lot of file open, shutdown overhead.
Code tracking:
1. index.php Entrance
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 ();
Using the reflection mechanism, instantiate the controller object and call the corresponding method
Attention:
Our CSS, JS, img images and other site resources, need to be accessed separately.
Making Web requests through routing
Template creation:
The controller calls the template to display the contents:
- Invoking a specific template through display ()
- Create the corresponding template file below the TPL directory creation
- Modify template file css and img image directory address, CSS style image address modification
- Make CSS, IMG, JS constants for template use in portal file index.php
Now the entry file:
Summarize:
- Create an application using the TP framework and make a portal file (go/index.php)
- To create multiple controllers, refer to the index controller. All controllers have inherited action parent class
- Call the view template display () through the controller
- Show Template content
Create a template below the TPL
Modify CSS, img corresponding directory address