自定义表单
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
59
application/index/controller/Form.php
Normal file
59
application/index/controller/Form.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user