What frame:
A bunch of code collection, inside there are variables, functions, classes, constants, there are many design patterns MVC, AR database, Singleton and so on.
The framework can save us the 50-60% of our work, and all of our energies are focused on the business level.
Other relevant frameworks
- 1. Zendframework Zend PHP Language Company released the official framework, heavyweight (multi-function)
- 2. Yii American Chinese Development Framework, Xue Qiang, Qiang, heavyweight framework, pure OOP framework
- 3. CI CodeIgniter Lightweight framework, fast development, flexible deployment
- CakePHP foreign frame, heavyweight, slow
- Symfony Foreign Heavyweight Framework
- Thinkphp lightweight frame, Chinese frame, easy to get started
"Framework Project Deployment"
Steps:
To create a portal file:
- Create a portal file under the thinkphp directory index.php
- While accessing the portal file, the system automatically creates the corresponding application catalog file shop.
- Open home Folder
"MVC pattern"
M:model Data Model layer, responsible for data manipulation
V:view view layer, responsible for displaying the view
C:controller Controller for business logic
"Controller access and routing resolution"
Locate the specified controller through the URL address get parameter and make the corresponding method call request
HTTP//URL/index.php?m= module name &c= Controller &a= method
The above URL address information code is not elegant, not secure.
The TP frame URL address can be made up of the following four
- HTTP//URL/index.php?m=xx&c=xx&a=xx basic Get mode
- http://Address/index.php/module/Controller/operation method path mode PathInfo (default)
- http://module/Controller/operation method rewrite override mode
- HTTP//URL/index.php?s=/module/controller/method Compatibility mode
Action: The method that is placed inside the controller
previously accessed by: access to specific pages
MVC Access: access to the operation under the Controller (method), not a specific page
Specific URL address mode settings (config file thinkphp/conf/convertion.php)
Url_model = 0/1/2/3 represents four URL address modes respectively
Config.php is the configuration file for our current project, and we can modify the file to reach the directory of configuration variables.
This file will overwrite the convertion.php configuration variables during system operation.
Include "convertion.php";
Include "config.php"; After the introduction of the file to the first introduction of the file configuration variables to cover out
MVC : Convention is better than configuration
Our system is compatible with the use of 4 URL address mode
The system will sometimes automatically create a URL address, which will be created using the URL address according to the current schema
Shortcut function u (); Create a URL address
We learned the following from the URL address pattern:
- We learned the configuration variables (core configuration variable conversion.php, current application configuration variable config.php)
- The shortcut function u ("module/Controller/method") creates the corresponding URL address according to the parameter and URL pattern
- Adjust the frame mode to develop debug mode
"Development, production model"
Development Debug Mode: The system needs to load about 24 files index.php define ("App_debug", true);
Production mode: The system only needs to load very little about 7 files in the portal file
index.php defined in: Define ("App_debug", false);
Save resources by saving a lot of file development, shutting down the system overhead
"Controller and corresponding method creation"
The controller is the core of the MVC pattern, and TP has an index controller by default:
The index controller has an operation method: Index
When we access the http://localhost:8080/Thinkphp/index.php portal file, we will access the index method under the index controller by default.
If you want to create a controller yourself login:
- Create a new controller file under the \shop\home\controller folder LoginController.class.php
Note: File naming rules, named according to the Hump method
IndexController.class.php Capitalize first letter
2. Open the file, build the controller login class inside
3. If you want to customize the action method, add a function login () to the Controller login class:
In this way we have completed the establishment of the controller and operation method, if you want to access our login controller under the login method:
4. In the controller if you want to invoke the template in the view layer:
If you visit again, you will find an error:
Cause: The template file is not created and we are going to create the template file
"View Template file Creation"
The view template files are stored in the following locations:
There are no template files inside
If we want to access the login method in the login controller, we will first create a template folder corresponding to the login controller, which corresponds to the login controller:
Then create a login.html template file under the Login folder to correspond to the login method under the login controller:
Write the code to be displayed in the login.html:
< Body > < H1 >Hello login</H1></body>
Then ask again:
"URL address case Settings"
The default is not sensitive:
Setting URL-case sensitivity in config.php
And then egg!!!
"System Constant Information"
Get System Constant Information:
If the argument is true, the display is grouped:
Var_dump (Get_define_constants (true));
Thinkphp Framework Foundation