NavcatController.class.php
2.0 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class NavcatController extends AdminbaseController {
protected $navcat_model;
public function _initialize() {
parent::_initialize();
$this->navcat_model =D("Common/NavCat");
}
// 导航分类显示
public function index() {
$cats=$this->navcat_model->select();
$this->assign("navcats",$cats);
$this->display();
}
// 导航分类添加
public function add() {
$this->display();
}
// 导航分类添加提交
public function add_post() {
if (IS_POST) {
if(empty($_POST['active'])){
$_POST['active']=0;
}else{
$this->navcat_model->where("active=1")->save(array("active"=>0));
}
if ($this->navcat_model->create()!==false) {
if ($this->navcat_model->add()!==false) {
$this->success("添加成功!", U("navcat/index"));
} else {
$this->error("添加失败!");
}
} else {
$this->error($this->navcat_model->getError());
}
}
}
// 导航分类编辑
public function edit(){
$id= I("get.id",0,'intval');
$navcat=$this->navcat_model->where(array('navcid'=>$id))->find();
$this->assign($navcat);
$this->display();
}
// 导航分类编辑提交
public function edit_post(){
if (IS_POST) {
if(empty($_POST['active'])){
$_POST['active']=0;
}else{
$this->navcat_model->where("active=1")->save(array("active"=>0));
}
if ($this->navcat_model->create() !== false) {
if ($this->navcat_model->save() !== false) {
$this->success("保存成功!", U("navcat/index"));
} else {
$this->error("保存失败!");
}
} else {
$this->error($this->navcat_model->getError());
}
}
}
// 删除导航分类
public function delete(){
$id = I("get.id",0,'intval');
if ($this->navcat_model->where(array('navcid'=>$id))->delete()!==false) {
$nav_obj=D("Common/Nav");
$nav_obj->where(array('cid'=>$id))->delete();
$this->success("删除成功!");
} else {
$this->error("删除失败!");
}
}
}