>[success] 模型会自动对应数据表,模型类的命名规则是除去表前缀的数据表名称,采用驼峰法命名,并且首字母大写 | 模型名 | 约定对应数据表(假设数据库的前缀定义是`zq_`) | | --- | --- | | User| zq_user | | UserType | zq_user_type | >[danger] 如果你的规则和上面的系统约定不符合,那么需要设置Model类的数据表名称属性,以确保能够找到对应的数据表。 ``` <?php namespace app\model; use think\Model; class UserModel extends Model { protected $name = 'user'; // 设置当前模型对应的完整数据表名称 protected $table = 'zq_user'; } ``` >[success] 模型类开启支持自动写入创建和更新的时间戳字段 ``` protected $autoWriteTimestamp = true; protected $createTime = 'ctime'; protected $updateTime = 'utime'; ``` >[success] 模型类开启软删除,软删除的作用就是把数据加上删除标记,而不是真正的删除,同时也便于需要的时候进行数据的恢复。 ``` //软删除位 use SoftDelete; protected $deleteTime = 'is_del'; //设置软删除字段的默认值 protected $defaultSoftDelete = 0; ``` >[success] 在App/common/model目录下创建用户模型Manage.php,完整代码如下: ``` <?php // +---------------------------------------------------------------------- // | najing [ 通用后台管理系统 ] // +---------------------------------------------------------------------- // | Copyright (c) 2020 http://www.najingquan.com All rights reserved. // +---------------------------------------------------------------------- // | Author: 救火队队长 // +---------------------------------------------------------------------- namespace app\common\model; use think\model\concern\SoftDelete; class Manage extends Common { //时间自动存储 protected $autoWriteTimestamp = true; protected $createTime = 'ctime'; protected $updateTime = 'utime'; //软删除位 use SoftDelete; protected $deleteTime = 'is_del'; //设置软删除字段的默认值 protected $defaultSoftDelete = 0; } ```