1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace addons\blog\model;
- use think\Model;
- class Category extends Model
- {
- // 表名
- protected $name = 'blog_category';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- // 追加属性
- protected $append = [
- 'url'
- ];
- protected static function init()
- {
- self::afterInsert(function ($row) {
- $row->save(['weigh' => $row['id']]);
- });
- }
- public function getStatusList()
- {
- return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getUrlAttr($value, $data)
- {
- $diyname = $data['diyname'] ? $data['diyname'] : $data['id'];
- return addon_url('blog/category/index', [':id' => $data['id'], ':diyname' => $diyname]);
- }
- }
|