src/PHPDish/Bundle/PostBundle/Controller/BookController.php
public function editChapterAction($slug, $id, Request $request)
    {
        $book = $this->getBookManager()->findBook($slug);
        $this->denyAccessUnlessGranted('edit', $book);

        //创建from
        $chapter = $this->getBookManager()->findChapter($id);
        $form = $this->createForm(ChapterType::class, $chapter, [
            'book' => $book,
        ]);
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            /**@var TranslatorInterface*/
            $translator = $this->get('translator');

            if ($this->getPostManager()->savePost($chapter)) {
                $this->addFlash('success', $translator->trans('book.edit_chapter_success'));
                return $this->redirectToRoute('book_summary', [
                    'slug' => $slug
                ]);
            } else {
                $this->addFlash('error', $translator->trans('book.edit_chapter_error'));
            }
        }
        return $this->render($this->configuration->getTemplate('Book:create_chapter.html.twig'), [
            'form' => $form->createView(),
            'chapter' => $chapter
        ]);
    }
public function editChapterAction($slug, $id, Request $request)
    {
        $book = $this->getBookManager()->findBook($slug);
        $this->denyAccessUnlessGranted('edit', $book);

        //创建from
        $chapter = $this->getBookManager()->findChapter($id);
        $form = $this->createForm(ChapterType::class, $chapter, [
            'book' => $book,
        ]);
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            /**@var TranslatorInterface*/
            $translator = $this->get('translator');

            if ($this->getPostManager()->savePost($chapter)) {
                $this->addFlash('success', $translator->trans('book.edit_chapter_success'));
                return $this->redirectToRoute('book_summary', [
                    'slug' => $slug
                ]);
            } else {
                $this->addFlash('error', $translator->trans('book.edit_chapter_error'));
            }
        }
        return $this->render($this->configuration->getTemplate('Book:create_chapter.html.twig'), [
            'form' => $form->createView(),
            'chapter' => $chapter
        ]);
    }
修改章节

@Route("/books/{slug}/chapters/{id}/edit", name="book_edit_chapter")
@param string  $slug
@param int $id
@param Request $request

@return Response