/** * 删除数据 */ function del() { //implode序列化主键Id为:1,2,3,...以便批量删除 $del_id = $_POST['del_id']; $catid = implode($del_id, ','); //实例化模型 $category = new CategoryModel(); $article = new ArticleModel(); $menu_items = new MenuItemModel(); //删除分类 if ($category->delete($catid)) { //删除文章的where语句 $where = array('catid' => array('in', $catid)); //删除文章 $article->where($where)->delete(); //删除类别后删除菜单项中的类别 $menu_where = array('type_id' => array('in', $catid), 'type' => 'Category'); $menu_items->where($menu_where)->delete(); $this->assign('jumpUrl', __URL__ . '/index'); $this->success('分类,下属文章以及相应的菜单项删除成功~~~~'); } else { $this->assign('jumpUrl', __URL__ . '/index'); $this->error('分类删除失败!' . $category->getError()); } }
/** * 单元删除页面 */ function del() { //因为删除一个单元,就要删除其手下的分类类别,而删除分类类别后就要删除该类别下面的文章 //所有必须使用关联操作来执行 //序列化主键Id为:1,2,3,...以便批量删除 $del_id = $_POST['del_id']; $section_id = implode($del_id, ','); //实例化 $section = new SectionModel(); $category = new CategoryModel(); $article = new ArticleModel(); $menu_items = new MenuItemModel(); //如果单元删除成功 if ($section->delete($section_id)) { //删除下属分类以及分类下属文章 $where = array('sectionid' => array('in', $section_id)); //删除分类 $category->where($where)->delete(); //删除文章 $article->where($where)->delete(); //删除单元后删除菜单项中的单元 $menu_where = array('type_id' => array('in', $section_id), 'type' => 'Section'); $menu_items->where($menu_where)->delete(); $this->assign('jumpUrl', __URL__ . '/index'); $this->success('单元,菜单项以及所有相关文章类别已删除~~~~'); } else { $this->assign('jumpUrl', __URL__ . '/index'); $this->error('删除失败~~~~' . $category->getError()); } }