-
Notifications
You must be signed in to change notification settings - Fork 3
/
BooksController.class.php
75 lines (63 loc) · 1.86 KB
/
BooksController.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 BooksController extends Controller{
public function index(){
$booksModel=M('books');
$books=$booksModel->select();
$this->assign('books',$books);
$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{
$booksModel=M('books');
$data=$booksModel->create();
//设置thumb字段属性
$data['thumb']=$info['thumb']['savepath'].$info['thumb']['savename'];
//添加
if($booksModel->add($data)){
$this->success('数据添加成功','index');
}else{
$this->showError('数据添加失败');
}
}
}
public function edit(){
$id=I('id');
$booksModel=M('books');
$data=$booksModel->find($id);
$this->assign('books',$data);
$this->display();
}
public function update(){
$booksModel=M('books');
$data=$booksModel->create();
if ($booksModel->save($data)) {
$this->success('课本更新成功','index');
}else{
this->error('课本更新失败');
}
}
public function delete(){
$id=I('id');
$booksModel=M('books');
if($booksModel->where("id=$id")->delete()){
$this->success('删除成功');
}else{
$this->showError('删除失败');
}
}
}
?>