创建模型

我们约定每张表必须对应一个模型,还是以示例模块为例,以上一步的文章分类表example_cate为例,应该在actionphp/application/example/model目录下创建模型文件Cate.php,文件内容如下:

创建模型 - 图1

注意namespace app\core\cate;class Cate extends Commonprotected $table = 'ia_example_cate';需要根据实际情况修改。

  1. <?php
  2. /**
  3. * +----------------------------------------------------------------------
  4. * | InitAdmin/actionphp [ InitAdmin渐进式模块化通用后台 ]
  5. * +----------------------------------------------------------------------
  6. * | Copyright (c) 2018-2019 http://initadmin.net All rights reserved.
  7. * +----------------------------------------------------------------------
  8. * | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  9. * +----------------------------------------------------------------------
  10. * | Author: jry <ijry@qq.com>
  11. * +----------------------------------------------------------------------
  12. */
  13. namespace app\core\cate;
  14. use app\core\model\Common;
  15. use think\Model;
  16. use think\model\concern\SoftDelete;
  17. class Cate extends Common
  18. {
  19. // 设置当前模型对应的完整数据表名称
  20. protected $table = 'ia_example_cate';
  21. public static function init()
  22. {
  23. parent::init();
  24. }
  25. // 软删除
  26. use SoftDelete;
  27. protected $deleteTime = 'delete_time';
  28. protected $defaultSoftDelete = 0;
  29. }