Home > Article > PHP Framework > what is model in thinkphp
In thinkphp, model refers to enterprise data and business rules. In actual project development, it mainly implements operations with the database; the naming of the model class needs to remove the database name of the table prefix and use camel case naming, and The first letter is capitalized, and the model class completes basic CURD, ActiveRecord mode, coherent operations, and statistical queries.
The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.
Model (Model) is a very important concept in ThinkPHP, and it is also related to the definition and instantiation of the model.
MVC is a method of separating the logical layer and presentation layer of an application. ThinkPHP is also based on the MVC design pattern. The definition of model (M) in ThinkPHP is completed by the Model class.
The basic model class in ThinkPHP is the Model class, which completes basic CURD, ActiveRecord mode, coherent operations, statistical queries, etc.
1. What is a model?
The model represents enterprise data and business rules. In actual project development, it mainly implements operations with the database.
2. Model definition rules
The naming rule of the model class is to remove the table prefix from the data table name, use camel case naming, and capitalize the first letter, and then add Enter the keyword Model of the model class, plus the class file suffix .class.php
Case: Implementing the organizational structure function of the mobile office automation system
1. Design database db_think
2. Design data table structure (tk_dept)
3. Use SQL statements to create data tables
4 .Create a Dept controller
5.Import the add.html template to the ./Application/Admin/View/Dept folder
6.Change Images/css/js path information in the add.html page
7. Change the left navigation link of the office system, knowledge points to be used:
U method
Main function: used to generate navigation links, such as /index.php/Admin/Dept/add, the usage method is as follows
In actual project development we usually use the third type Method, U('module/controller/operation method')
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of what is model in thinkphp. For more information, please follow other related articles on the PHP Chinese website!