diff --git a/application/system/controller/SystemBase.php b/application/system/controller/SystemBase.php index 37305b20..33953cc2 100644 --- a/application/system/controller/SystemBase.php +++ b/application/system/controller/SystemBase.php @@ -13,11 +13,9 @@ class SystemBase extends Base // 系统设置 public function index() { - $count = 1; // 设置要给模板赋值的信息 $list['title'] = '系统设置'; - $list['count'] = $count; // 模板赋值 $this->assign('list',$list); @@ -72,13 +70,41 @@ class SystemBase extends Base // 编辑系统设置 public function edit($id) { - return 'aa'; + // 获取用户信息 + $list = sysbasemod::field('id,title,keywords,description,copyright,thinks,danwei') + ->get($id); + + + $this->assign('list',$list); + + return $this->fetch(); } // 更新资源 - public function update(Request $request, $id) + public function update($id) { - // + $validate = new \app\system\validate\SystemBase; + + // 获取表单数据 + $list = request()->only(['title','keywords','description','copyright','thinks','danwei'],'put');; + + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + + $data = sysbasemod::where('id',$id)->update($list); + + // 根据更新结果设置返回提示信息 + $data>=0 ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } diff --git a/application/system/validate/SystemBase.php b/application/system/validate/SystemBase.php new file mode 100644 index 00000000..2a2b0c20 --- /dev/null +++ b/application/system/validate/SystemBase.php @@ -0,0 +1,31 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = [ + 'title|标题' => 'require|length:2,50', + 'keywords|关键字' => 'require|length:2,60', + 'description|描述' => 'require|length:1,100', + 'copyright|版权' => 'require|length:1,15', + 'thinks|感谢' => 'require|length:1,80', + 'danwei|单位' => 'require|length:2,80', + ]; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = []; +} diff --git a/application/system/view/system_base/create.html b/application/system/view/system_base/create.html deleted file mode 100644 index 22f99691..00000000 --- a/application/system/view/system_base/create.html +++ /dev/null @@ -1,117 +0,0 @@ -{extend name="common@create" /} -{block name="formaa"} -
-{/block} -{block name="yanzheng"} - -{/block} \ No newline at end of file diff --git a/application/system/view/system_base/edit.html b/application/system/view/system_base/edit.html index 28aa393f..07fc510c 100644 --- a/application/system/view/system_base/edit.html +++ b/application/system/view/system_base/edit.html @@ -1,66 +1,40 @@ {extend name="common@create" /} {block name="formaa"} -