Category.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace addons\blog\model;
  3. use think\Model;
  4. class Category extends Model
  5. {
  6. // 表名
  7. protected $name = 'blog_category';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. 'url'
  16. ];
  17. protected static function init()
  18. {
  19. self::afterInsert(function ($row) {
  20. $row->save(['weigh' => $row['id']]);
  21. });
  22. }
  23. public function getStatusList()
  24. {
  25. return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
  26. }
  27. public function getStatusTextAttr($value, $data)
  28. {
  29. $value = $value ? $value : $data['status'];
  30. $list = $this->getStatusList();
  31. return isset($list[$value]) ? $list[$value] : '';
  32. }
  33. public function getUrlAttr($value, $data)
  34. {
  35. $diyname = $data['diyname'] ? $data['diyname'] : $data['id'];
  36. return addon_url('blog/category/index', [':id' => $data['id'], ':diyname' => $diyname]);
  37. }
  38. }