diff --git a/application/system/controller/Category.php b/application/system/controller/Category.php index c53205a6..e25c3095 100644 --- a/application/system/controller/Category.php +++ b/application/system/controller/Category.php @@ -53,6 +53,13 @@ class Category extends Base //查询数据 $data =CG::field('id,title,pid,status,paixu') ->order([$order_field=>$order]) + ->with( + [ + 'glPid'=>function($query){ + $query->field('id,title'); + }, + ] + ) ->limit($limit_start,$limit_length) ->all(); @@ -64,6 +71,13 @@ class Category extends Base ->whereOr('pid','in',function($query) use ($search){ $query->name('category')->where('title','like','%'.$search.'%')->field('id'); }) + ->with( + [ + 'glPid'=>function($query){ + $query->field('id,title'); + }, + ] + ) ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) ->select(); diff --git a/application/system/model/Category.php b/application/system/model/Category.php index 97cc7311..6c3ce2b5 100644 --- a/application/system/model/Category.php +++ b/application/system/model/Category.php @@ -9,9 +9,15 @@ class Category extends Base // 关闭全局自动时间戳 protected $autoWriteTimestamp = false; - // 父级类别获取器 - public function getPidAttr($value) + // // 父级类别获取器 + // public function getPidAttr($value) + // { + // return $this->where('id',$value)->value('title'); + // } + + // 本模型关联 + public function glPid() { - return $this->where('id',$value)->value('title'); + return $this->belongsTo('Category','pid','id'); } } diff --git a/application/system/view/category/edit.html b/application/system/view/category/edit.html index 6a0d0189..47a8ea8f 100644 --- a/application/system/view/category/edit.html +++ b/application/system/view/category/edit.html @@ -16,7 +16,7 @@ diff --git a/application/system/view/category/index.html b/application/system/view/category/index.html index 2e8f250b..f2c1ab80 100644 --- a/application/system/view/category/index.html +++ b/application/system/view/category/index.html @@ -61,9 +61,9 @@ // 定义列参数 var mycolumns = [ - { "data": "id" }, - { "data": "title" }, - { "data": "pid" }, + { "data": "id" ,"name":"id","defaultContent": "" }, + { "data": "title" ,"name":"title","defaultContent": "" }, + { "data": "gl_pid.title" ,"name":"pid","defaultContent": "" }, { "data": "paixu" }, { "data": "status" }, { "data": "id" }, diff --git a/database/seeds/Category.php b/database/seeds/Category.php index dda675ac..daee202e 100644 --- a/database/seeds/Category.php +++ b/database/seeds/Category.php @@ -29,7 +29,7 @@ class Category extends Seeder ['id'=>110,'title'=>'学科','pid'=>0,'paixu'=>10], ['id'=>111,'title'=>'文件','pid'=>0,'paixu'=>11], ['id'=>112,'title'=>'单位荣誉类型','pid'=>0,'paixu'=>12], - ['id'=>113,'title'=>'单位荣誉奖项','pid'=>0,'paixu'=>13], + ['id'=>113,'title'=>'荣誉奖项','pid'=>0,'paixu'=>13], ['id'=>114,'title'=>'教师荣誉类型','pid'=>0,'paixu'=>14], ['id'=>115,'title'=>'课题立项类型','pid'=>0,'paixu'=>15], ['id'=>116,'title'=>'课题研究所属学科分类','pid'=>0,'paixu'=>16,], @@ -127,6 +127,8 @@ class Category extends Seeder ['title'=>'三等奖','pid'=>113,'paixu'=>4], ['title'=>'优秀奖','pid'=>113,'paixu'=>5], ['title'=>'百十佳','pid'=>113,'paixu'=>6], + ['title'=>'指导奖','pid'=>113,'paixu'=>7], + ['title'=>'其他','pid'=>113,'paixu'=>8], // 教师荣誉分类 ['title'=>'优质课','pid'=>114,'paixu'=>1], ['title'=>'技能大赛','pid'=>114,'paixu'=>2],