model model database operation
The main design pattern of tp framework: MVC
C:controller shop/Lib/Action/specific controller
V:view shop/Tpl/group/template file
M: model Data model shop/Lib/Model/Specific model
Principle of creation: one data table corresponds to one data model
Create model:
When the following message appears, it means that our database does not have a username and password configured in config.php
We use the select() method to obtain data information from the database, which returns a two-dimensional array,
If we want to get a record, use the find() method, which returns a one-dimensional array
$goods -> select() //Get all records and all field results
$goods -> select(15) //Get the record results with the primary key equal to 15
$goods -> select(“10,15,20”) //Get the record information with the primary key within the range of 10, 15, 20
$goods -> find(16); //Return to us the record information with the primary key equal to 16 in the form of a one-dimensional array
$goods -> getByXXX(); //Query based on the where condition of the specific XXX field, and the one-dimensional array result is returned. This method will use the __call() automatic condition method in Model.class.php.
For example: D(‘Goods’); Instantiate the Goods model object
D(); Instantiate the base class object. When using this object, you need to specify the "data table name"
and primary key names are more complicated and are not recommended to be used directly
3 Instantiate the base class object through the shortcut function M()
For example: M() instantiates the object corresponding to Model.class.php. This method is not recommended