BaseModel.php 484 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 道行
  5. * Date: 2021-01-17
  6. * Time: 17:46
  7. */
  8. namespace app\model;
  9. use think\Model;
  10. class BaseModel extends Model
  11. {
  12. //返回模型实例
  13. public static function getInstance()
  14. {
  15. return new static();
  16. }
  17. //获取某一条数据
  18. public function getOne($where)
  19. {
  20. if (!is_array($where)) {
  21. $where = [$this->getPk() => $where];
  22. }
  23. return $this->where($where)->find();
  24. }
  25. }