public function editAction() { $p = $_REQUEST; $pId = empty($p['id']) ? die('ID不能为空') : intval($p['id']); $tMO = new CategoryModel(); $tCateRow = $tMO->field('*')->where('id = ' . $pId)->fRow(); if ($_SERVER['REQUEST_METHOD'] == "POST") { $pTitle = empty($p['title']) ? Tool_Fnc::ajaxMsg('分类标题不能为空') : Tool_Fnc::safe_string($p['title']); $pName = empty($p['name']) ? Tool_Fnc::ajaxMsg('分类别名不能为空') : Tool_Fnc::safe_string($p['name']); $pPid = empty($p['pid']) ? 0 : intval($p['pid']); $pKeywords = empty($p['keywords']) ? '' : Tool_Fnc::safe_string($p['keywords']); $pDescription = empty($p['description']) ? '' : Tool_Fnc::safe_string($p['description']); $tTime = time(); if (!count($tCateRow)) { Tool_Fnc::ajaxMsg('分类不存在'); } $tRow = $tMO->field('count(0) c')->where('name = \'' . $pName . '\' and id <> ' . $pId)->fRow(); if (!empty($tRow['c'])) { Tool_Fnc::ajaxMsg('分类别名不能和其他分类重名'); } $tData = array('title' => $pTitle, 'name' => $pName, 'pid' => $pPid, 'keywords' => $pKeywords, 'description' => $pDescription, 'updated' => $tTime, 'id' => $pId); if (!$tMO->update($tData)) { Tool_Fnc::ajaxMsg('修改失败'); } Tool_Fnc::ajaxMsg('修改成功', 1); } $tDatas = $tMO->field('id,pid,name,title')->fList(); $this->assign('tCatelist', Tool_Fnc::getSortedCategory($tDatas)); $this->assign('tId', $pId); $this->assign('tCateRow', $tCateRow); }
//第一步:后台检查数据 if (empty($_POST['cat_name'])) { exit('category name has to be set'); } //第二步:接受数据 $cat_id = $_POST['cat_id']; $data['cat_name'] = $_POST['cat_name']; $data['dscrpt'] = $_POST['cat_desc']; $data['parent_id'] = $_POST['parent_id'] + 0; /* 检查修改后的数据是否引起闭环 */ $cat = new CategoryModel(); $catlist = $cat->getList(); $trees = $cat->getTree($catlist, $data['parent_id']); //echo $cat_id."修改后上层栏目页是".$data['parent_id']."<br>"; $canupdate = true; foreach ($trees as $v) { if ($v['cat_id'] == $cat_id) { $canupdate = false; } } if (!$canupdate) { echo 'Error: Cannot update ' . $cat_id . '是' . $data['parent_id'] . '的祖先<br>'; exit; } if ($cat->update($cat_id, $data) != -1) { echo "category updated successfully"; } else { echo "category updated unsuccessfully"; }
function act_delCategory() { $id = trim($_POST['id']); if (CategoryModel::getCategoryList("*", "where is_delete=0 and pid='{$id}'")) { self::$errCode = 03; self::$errMsg = '请先删除子分类!'; return false; } else { $where = "and `id` = '{$id}'"; $data = array('is_delete' => 1); if (CategoryModel::update($data, $where)) { return true; } else { self::$errCode = 03; self::$errMsg = '删除失败,请重试!'; return false; } } }