protected function handle() { $structure = StructureModel::getStructure($this->id); $request = $this->getRequest(); if ($request->getMethod() == 'POST') { $posts = $request->request; $session = $this->getSession(); try { $name = $posts->get('name'); // 检查search是否重复 $search = $request->request->get('search'); if ($search) { $s = StructureModel::search($search); if ($s->id != $this->id) { throw new \Exception("键名为 {$search} 的目录结构已存在"); } } else { $search = null; } $description = $posts->get('description'); if (!$name) { throw new \Exception("结构名称不能为空"); } $type = $posts->get('type'); if (!$type) { throw new \Exception("结构类型不能为空"); } if (!StructureTypeBusiness::isValid($type)) { throw new \Exception("结构类型错误"); } $metadata = $posts->get('metadata'); $structure->name = $name; $structure->search = $search; $structure->description = $description; $structure->type = $type; $structure->metadata = $metadata; $structure->updateTimestamp = time(); StructureModel::saveStructure($structure); $session->addFlash('success', '编辑成功'); } catch (\Exception $e) { $session->addFlash('error', $e->getMessage()); } return new RedirectResponse($this->generateUrl('admin_www_structure')); } return $this->render('structure/edit.html.twig', array('structure' => $structure)); }