diff --git a/app/controller/admin/Content.php b/app/controller/admin/Content.php index 61b7444a..687cf6b0 100644 --- a/app/controller/admin/Content.php +++ b/app/controller/admin/Content.php @@ -34,12 +34,17 @@ class Content extends Base { * @author molong */ public function index() { + $param = $this->request->param(); if ($this->modelInfo['list_grid'] == '') { return $this->error("列表定义不正确!", url('/admin/model/edit', array('id' => $this->modelInfo['id']))); } $order = "id desc"; $map = []; + if (isset($param['keyword']) && $param['keyword'] != '') { + $map[] = ['title', 'LIKE', '%'.$param['keyword'].'%']; + } + $list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row'], false, array( 'query' => $this->request->param(), )); @@ -50,7 +55,8 @@ class Content extends Base { 'page' => $list->render(), 'model_name' => $this->modelInfo['name'], 'model_id' => $this->modelInfo['id'], - 'meta_title' => $this->modelInfo['title'].'列表' + 'meta_title' => $this->modelInfo['title'].'列表', + 'param' => $param ); if ($this->modelInfo['template_list']) { $template = 'admin/content/' . $this->modelInfo['template_list']; diff --git a/app/controller/user/Content.php b/app/controller/user/Content.php index 44a048fb..63e93eb9 100644 --- a/app/controller/user/Content.php +++ b/app/controller/user/Content.php @@ -31,12 +31,16 @@ class Content extends Base { * @return [type] [description] */ public function index() { + $param = $this->request->param(); if ($this->modelInfo['list_grid'] == '') { return $this->error("列表定义不正确!", url('/user/model/edit', array('id' => $this->modelInfo['id']))); } $order = "id desc"; $map = []; $map[] = ['uid', '=', session('userInfo.uid')]; + if (isset($param['keyword']) && $param['keyword'] != '') { + $map[] = ['title', 'LIKE', '%'.$param['keyword'].'%']; + } $list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row'], false, array( 'query' => $this->request->param(), @@ -48,7 +52,8 @@ class Content extends Base { 'page' => $list->render(), 'model_name' => $this->modelInfo['name'], 'model_id' => $this->modelInfo['id'], - 'meta_title' => $this->modelInfo['title'].'列表' + 'meta_title' => $this->modelInfo['title'].'列表', + 'param' => $param ); if ($this->modelInfo['template_list']) { $template = 'user@content/' . $this->modelInfo['template_list']; @@ -64,9 +69,34 @@ class Content extends Base { */ public function add() { if ($this->request->isPost()) { - # code... + $data = $this->request->post(); + $data['create_time'] = time(); + $data['update_time'] = time(); + $data['uid'] = session('userInfo.uid'); + + $result = $this->model->save($data); + if ($result) { + return $this->success("添加成功!", url('/user/'.$this->modelInfo['name'].'/index')); + } else { + return $this->error('添加失败!'); + } }else{ - return $this->fetch(); + $info = [ + 'model_name' => $this->modelInfo['name'], + 'model_id' => $this->modelInfo['id'] + ]; + $this->data = [ + 'info' => $info, + 'fieldGroup' => Attribute::getField($this->modelInfo), + 'meta_title' => $this->modelInfo['title'].'添加' + ]; + + if ($this->modelInfo['template_add']) { + $template = 'user/content/' . $this->modelInfo['template_add']; + } else { + $template = 'user@/edit'; + } + return $this->fetch($template); } } @@ -74,11 +104,37 @@ class Content extends Base { * @title 修改内容 * @return [type] [description] */ - public function edit() { + public function edit($id) { if ($this->request->isPost()) { - # code... + $data = $this->request->post(); + $data['update_time'] = time(); + + $result = $this->model->save($data); + if ($result !== false) { + return $this->success("更新成功!", url('/user/'.$this->modelInfo['name'].'/index')); + } else { + return $this->error('修改失败!'); + } }else{ - return $this->fetch(); + if (!$id) { + return $this->error("非法操作!"); + } + $info = $this->model->find($id); + if (!$info) { + return $this->error('无此数据!'); + } + $info['model_id'] = $this->modelInfo['id']; + $this->data = array( + 'info' => $info, + 'fieldGroup' => Attribute::getField($this->modelInfo, 'edit'), + 'meta_title' => $this->modelInfo['title'].'修改' + ); + if ($this->modelInfo['template_edit']) { + $template = 'user/content/' . $this->modelInfo['template_edit']; + } else { + $template = 'user@/edit'; + } + return $this->fetch('user@/edit'); } } @@ -87,5 +143,6 @@ class Content extends Base { * @return [type] [description] */ public function del() { + return $this->error("无删除权限!"); } } \ No newline at end of file diff --git a/public/template/default/user/base.html b/public/template/default/user/base.html index 68bcfbcd..a37c5b7d 100644 --- a/public/template/default/user/base.html +++ b/public/template/default/user/base.html @@ -184,7 +184,7 @@ diff --git a/public/template/default/user/content_index.html b/public/template/default/user/content_index.html index 079b79c5..ed11b07a 100644 --- a/public/template/default/user/content_index.html +++ b/public/template/default/user/content_index.html @@ -3,12 +3,15 @@

{$meta_title}

+
+ 新 增 +
- +
{if isset($cate_list)}
@@ -56,8 +59,8 @@ {/if} {/volist} - 编辑 - 删除 + 编辑 + 删除 {/volist} diff --git a/view/admin/content/index.html b/view/admin/content/index.html index cbe2fe4b..6a0faa30 100644 --- a/view/admin/content/index.html +++ b/view/admin/content/index.html @@ -12,14 +12,14 @@
- +
{if isset($cate_list)}