thinkphp virtual model

Although the virtual model refers to the model class, but does not really model the database. Sometimes, we model the class but does not require a database operation, only the aid of the model class to encapsulate some business logic, you can use the virtual model to do so. Virtual model does not automatically connect to the database, and therefore does not automatically detect the data table and field information, there are two ways to define a virtual model:

Marble platform manufacturers

The first: Model class inheritance
  1. namespace Home\Model;
  2. Class UserModel extends \Think\Model {
  3. Protected $autoCheckFields = false;
  4. }

After setting autoCheckFields property is false, it will turn off the automatic detection fields of information, because the use of an inert ThinkPHP database connection, as long as you database query, the database is not connected.

The second: Model class does not inherit
  1. namespace Home\Model;
  2. Class UserModel {
  3. }

In this manner the following custom model class is a simple business logic classes, the method can not be used CURD operation model, but other models can instantiate classes related operations, may be directly instantiated when needed Db class database operating.

 

Guess you like

Origin www.cnblogs.com/furuihua/p/11813553.html