diff --git a/application/common/behavior/InitHook.php b/application/common/behavior/InitHook.php index 884febaf..940e2117 100644 --- a/application/common/behavior/InitHook.php +++ b/application/common/behavior/InitHook.php @@ -51,6 +51,8 @@ class InitHook { foreach ($list as $key => $value) { $route[$value['rule']] = $value['url']; } + + //模型类路由配置 $list = db('Model')->column('id,name', 'id'); foreach ($list as $key => $value) { $route["admin/" . $value . "/index"] = "admin/content/index?model_id=" . $key; @@ -67,8 +69,15 @@ class InitHook { $route["user/" . $value . "/del"] = "user/content/del?model_id=" . $key; $route["user/" . $value . "/status"] = "user/content/status?model_id=" . $key; } - $route["list/:id"] = "index/content/category"; + + //自定义表单路由配置 + $form = db('Form')->column('id,name', 'id'); + foreach ($form as $key => $value) { + $route["form/".$value."/index"] = "index/form/index?model=" . $value; + $route["form/".$value."/list"] = "index/form/lists?model=" . $value; + $route["form/".$value."/add"] = "index/form/add?model=" . $value; + } \think\Route::rule($route); } } \ No newline at end of file diff --git a/application/index/controller/Form.php b/application/index/controller/Form.php new file mode 100644 index 00000000..4d03baa9 --- /dev/null +++ b/application/index/controller/Form.php @@ -0,0 +1,59 @@ + +// +---------------------------------------------------------------------- + +namespace app\index\controller; +use app\common\controller\Fornt; + +class Form extends Fornt { + + public function _initialize() { + parent::_initialize(); + $model_name = $this->request->param('model'); + $this->model = M($model_name, 'form'); + } + + /** + * 表单首页 + */ + public function index(){ + return $this->fetch(); + } + + /** + * 表单列表 + */ + public function lists(){ + $list = $this->model->order('id desc')->paginate('20'); + + $data = array( + 'list' => $list, + 'page' => $list->render() + ); + $this->assign($data); + return $this->fetch(); + } + + + /** + * 表单数据提交 + */ + public function add(\think\Request $request){ + if ($request->isPost()) { + $data = $request->param(); + $result = $this->model->save($data); + if (false !== $result) { + return $this->success('提交成功!'); + }else{ + return $this->error('提交失败!'); + } + }else{ + return $this->fetch(); + } + } +} \ No newline at end of file