thinkphp Study notes (vi) Four ways to instantiate a model
This article is based on the thinkphp study Note (v) to modify, if a classmate use this code, please read the thinkphp study notes first (v)
Create an Action class
Select ();//dump ($list);////Two: cross-model operations; Instantiate a table and instantiate a database operation class of its own write//More used to draw out some common business logic to form a common model////m (' user ', ' Commonmodel ') is equivalent to new Commonmodel (' user '), model is automatically loaded////$user =m (' user ', ' Commonmodel ');//$user =new Commonmodel (' User ');//$list = $user->select ();//dump ($list);//$user->modeltest ();//Three: Instantiate a user-defined model//More for a business//1 that does not require more complexity. Create a model manually, create a custom model for the user table, and encapsulate the functionality provided by thinkphp//$user =new Usermodel () equivalent to D (' user '),//d method if the model does not exist, throws an exception, only instance one, default, Only support calls to the following model//$user =new Usermodel ();//$list = $user->select ();//dump ($list);//$user->modeltest ();//Iv. Instantiate an empty model, that is, the traditional way of SQL statements, need to add a table prefix//$user =new Model (), $list = $user->query (' select * from Tb_user ');d UMP ($list);//Group: D ( ' Admin.user ');}? >
Two models: