-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestsController.class.php
75 lines (63 loc) · 1.86 KB
/
TestsController.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Admin\Controller;
use Think\Controller;
class TestsController extends Controller{
public function index(){
$testsModel=M('tests');
$tests=$testsModel->select();
$this->assign('tests',$tests);
$this->display();
}
public function create(){
$this->display();
}
public function store(){
$upload= new \Think\Upload();//实例化上传类
$upload->maxsize=3145728;
$upload->exts= array('jpg','gif','png','jpeg');
$upload->rootPath = THINK_PATH;
$upload->savePath='../Public/uploads/';
//上传文件
$info = $upload->upload();
if(!$info){
$this->error($upload->getError());
}else{
$testsModel=M('tests');
$data=$booksModel->create();
//设置thumb字段属性
$data['thumb']=$info['thumb']['savepath'].$info['thumb']['savename'];
//添加
if($testsModel->add($data)){
$this->success('数据添加成功','index');
}else{
$this->showError('数据添加失败');
}
}
}
public function edit(){
$id=I('id');
$testsModel=M('tests');
$data=$testsModel->find($id);
$this->assign('tests',$data);
$this->display();
}
public function update(){
$testsModel=M('tests');
$data=$testsModel->create();
if ($testsModel->save($data)) {
$this->success('课本更新成功','index');
}else{
this->error('课本更新失败');
}
}
public function delete(){
$id=I('id');
$testsModel=M('tests');
if($testsModel->where("id=$id")->delete()){
$this->success('删除成功');
}else{
$this->showError('删除失败');
}
}
}
?>