public function editCate($id) { //$this->ajaxreturn(['msg'=>'修改成功'],'JSON'); //die(); $cate = new CateModel(); if (IS_POST) { $cate->create(); $cate->model = json_encode($cate->model); $cate->status = 1; //$this->ajaxreturn(['msg'=>$cate->where(['id'=>$id])->save()]); if ($cate->where(['id' => $id])->save()) { //return json_encode(['msg'=>'修改成功','status'=>1]); $this->ajaxreturn(['msg' => '修改成功']); } else { //return json_encode(['msg'=>'修功','status'=>2]); $this->ajaxreturn(['msg' => $cate->getError()]); } } else { $content = $cate->find($id); $checked = json_decode($content['model']); $this->assign($content); $model = get_all_model(); foreach ($model as $k => $v) { if (in_array($v['id'], $checked)) { $model[$k]['checked'] = "checked=true"; } } $this->assign('model', $model); $this->display(); } }
/** * 动态显示表中字段 */ public function ajax_info() { if (IS_AJAX) { if ($_POST['cateid'] == 'local') { $data['status'] = 1; $modellist = get_all_model($fields = 'name,id,title,extend'); foreach ($modellist as $key => $value) { if ($value['extend'] == 0) { $newlist[$key] = array_values($value); } } $data['msg'] = $newlist; } //$val['id'] if ($_POST['cateid'] == 'category') { $data['status'] = 1; $tree = D('Category')->getTree(0, 'id,title,pid,status'); $cate_list = array(); foreach ($tree as $key => $val) { if (is_array($val['_'])) { foreach ($val['_'] as $v) { if ($v['status'] == 1) { $cate_list[] = array($val['id'], $v['id'], $v['title']); } } } } $data['msg'] = $cate_list; } $this->ajaxReturn($data); } }