getRule($name)) { /* 更新 */ } else { /* 添加 */ $rule = new Rule(); $rule->name = $name; $this->add($rule); } /* 判断auth_item表是否存在 */ if ($item = $this->getItem($name)) { /* 更新 */ } else { /* 添加 */ $item = new Item(); $item->name = $name; $item->type = 2; $item->ruleName = $name; $this->add($item); } } /** * --------------------------------------- * 保存角色的权限分配 * @param string $parent 角色name * @param string $child 权限name * --------------------------------------- */ public function saveChild($parent, $child) { /* 判断auth_item_child表是否存在 */ $parent = $this->getRole($parent); $child = $this->getItem($child); if (!$this->hasChild($parent, $child)) { $this->addChild($parent, $child); } } /** * --------------------------------------- * 更新auth_item * @throws \Exception * --------------------------------------- */ protected function updateRule($name, $rule) { if ($rule->name !== $name && !$this->supportsCascadeUpdate()) { $this->db->createCommand()->update($this->itemTable, [ 'rule_name' => $rule->name, 'name' => $rule->name, ], ['rule_name' => $name])->execute(); } $rule->updatedAt = time(); $this->db->createCommand() ->update($this->ruleTable, [ 'name' => $rule->name, 'data' => serialize($rule), 'updated_at' => $rule->updatedAt, ], ['name' => $name,])->execute(); $this->invalidateCache(); return true; } }