protected function handle() { $thread_id = $this->threadId; $thread = ThreadModel::getThread($thread_id); if (!$thread) { throw new \Exception('帖子不存在'); } $request = $this->getRequest(); if ($request->getMethod() == 'POST') { $session = $this->getSession(); $db = ForumDatabase::getInstance(); $db->transaction(); try { // 删除帖子 ThreadModel::removeThread($thread); // 删除帖子的回复 PostModel::deletePosts(function (QueryBuilder $qb) use($thread_id) { $qb->andWhere($qb->expr()->eq('thread_id', ':thread_id'))->setParameter(':thread_id', $thread_id); }); $db->commit(); $session->addFlash('success', '删除成功'); } catch (\Exception $e) { $db->rollback(); $session->addFlash('error', $e->getMessage()); } return new RedirectResponse($this->generateUrl('admin_forum_thread_manage')); } return $this->render('thread/thread-delete.html.twig', array('thread' => $thread)); }