自定义表单
This commit is contained in:
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