1. instantiate a table. 1. create a basic model. instantiate a database class that comes with the system. UsernewModol (user) is equivalent to $ UserM (user ); 2. thinkphp will automatically help us find the table in this database, and take the table as the corresponding field.
I. instantiate a table
1. create a basic model, instantiate a database class that comes with the system & User = new Modol ('user') is equivalent to $ user = M ('user ');
2. thinkphp will automatically help us find the table in this database and take all the corresponding fields in the table, you can directly operate the table and use the methods in the table (add, delete, modify, and query) $ list = $ User-> select ()
II. instantiate a self-written custom database class and a table
- $ USER = M ('user', 'commonmodel'); equivalent to $ USER = new commonmodel ('user') // COMMONMODEL
- $ LIST = $ USER-> SELECT ();
- DUMP ($ LIST)
- $ USER-> ABD (); // methods in the COMMONMODEL class
3. instantiate a user-defined model
1. Custom model: // home/Lib/Action/
- Class UserModel extends Model {
- Function ad (){
- Echo 'aaaaaaaaaaa ';
- }
- }
2. instantiate the model:
Note:When instantiating a model, the table name and your class name (model) do not need to be input. in this case, the relevant fields of the table are obtained.
- $ User = new UserModel (); equivalent to $ user = D ('user ');
- $ List = $ user-> select (); // select () is inherited from Moel.
- Dump ($ list)
- $ User-> ad ();
4. strengthen an empty model:
- $ User = new Model ();
- $ List = $ user-> query ('select * from think_user '); // you must add a prefix to the table.
- Dump ($ list );