/** * 重写父类save方法 * @return bool */ public function save() { //验证目标分类下是否有同名子类 $where = array('parent_id' => $this->data['parent_id'], 'name' => $this->data['name'], 'id' => array('neq', $this->data['id'])); $myRow = $this->where($where)->select(); if (!empty($myRow)) { $this->error = '目标分类下有同名子类'; return false; } //验证目标分类是否是其自己及子孙分类 $id = $this->data['id']; $sql = "select c.id from goods_category as f,goods_category as c where f.id = {$id} and c.lft>=f.lft and c.rgt<=f.rgt;"; $myRow = $this->query($sql); $ids = array_column($myRow, 'id'); if (in_array($this->data['parent_id'], $ids)) { $this->error = '不能移动到其子孙分类中'; return false; } //处理边界问题,借助于netstetsets插件 $mydb = new DbImplementServer(); //得到实现接口的相关对象 $netstedsets = new NestedSetsServer($mydb, 'goods_category', 'lft', 'rgt', 'parent_id', 'id', 'level'); $netstedsets->moveUnder($this->data['id'], $this->data['parent_id'], 'bottom'); //保存其他数据 return parent::save(); }
/** * 重写save方法,结助嵌套集合实现 * @return bool */ public function save() { //处理边界问题,借助于netstetsets插件 $mydb = new DbImplementServer(); //得到实现接口的相关对象 $netstedsets = new NestedSetsServer($mydb, 'permission', 'lft', 'rgt', 'parent_id', 'id', 'level'); $netstedsets->moveUnder($this->data['id'], $this->data['parent_id'], 'bottom'); //保存其他数据 return parent::save(); }
/** * 重写save方法,修改菜单权限关系 * @return bool */ public function save($requestData) { //修改当前表,借助于netstetsets插件 $mydb = new DbImplementServer(); //得到实现接口的相关对象 $netstedsets = new NestedSetsServer($mydb, 'menu', 'lft', 'rgt', 'parent_id', 'id', 'level'); $netstedsets->moveUnder($this->data['id'], $this->data['parent_id'], 'bottom'); //保存其他数据 $result = parent::save(); if ($result === false) { return false; } //保存菜单权限关系 $rst = $this->handleMenuPermission($requestData['id'], $requestData['permission_ids']); if ($rst === false) { return false; } return $result; }