InitModel.php 706 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2020/6/5
  6. * Time: 下午4:13
  7. */
  8. namespace app\source\model;
  9. abstract class InitModel implements ModelInterface
  10. {
  11. //主键
  12. public $pk = '';
  13. public static $self;
  14. /**
  15. * 绑定参数
  16. * @param $data
  17. * @return static
  18. */
  19. public function bind($data)
  20. {
  21. foreach ($data as $key => $value) {
  22. $this->$key = $value;
  23. }
  24. return $this;
  25. }
  26. /**
  27. * 转化为数组
  28. * @return mixed
  29. */
  30. public function toArray()
  31. {
  32. $data = [];
  33. foreach ($this as $field => $value) {
  34. $data[$field] = $value;
  35. }
  36. return $data;
  37. }
  38. }