示例#1
0
 public function save()
 {
     if (is_numeric($this->id)) {
         $menu = TbMenu::findOne($this->id);
     } else {
         $menu = new TbMenu();
         $menu->fdAction = strval(rand(0, 9999));
     }
     $menu->fdClass = $this->class;
     $menu->fdName = $this->name;
     $menu->fdOrder = $this->order;
     $menu->fdPrivilege = $this->privilege;
     $menu->fdDisabled = $this->disabled;
     if (!$menu->save()) {
         echo json_encode(['code' => -1, 'msg' => json_encode($menu->errors, JSON_UNESCAPED_UNICODE)]);
         return false;
     }
     $menu->fdAction = "action" . $menu->id;
     $menu->save();
     TbMenuTable::deleteAll("fdMenuID = :id", [":id" => $this->id]);
     if (is_array($this->tables)) {
         foreach ($this->tables as $table) {
             $menu_table = new TbMenuTable();
             $menu_table->fdTableID = $table;
             $menu_table->fdMenuID = $menu->id;
             $menu_table->save();
         }
     }
     echo json_encode(['code' => 0, 'msg' => '请求操作成功', 'result' => ['id' => $menu->id]]);
     return true;
 }