src/PHPDish/Bundle/PostBundle/Controller/BookController.php
public function createAction(Request $request)
    {
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
        $manager = $this->getBookManager();

        $book = $manager->createBook($this->getUser());
        $form = $this->createForm(BookType::class, $book);
        $form->handleRequest($request);

        /**@var TranslatorInterface*/
        $translator = $this->get('translator');
        if (($number = $manager->getUserBookNumber($this->getUser())) >= 5) {
            $this->addFlash('danger', $translator->trans('book.more_than_5_books', ['%count%' => $number]));
        }

        if ($form->isSubmitted() && $form->isValid()) {
            $manager->saveBook($book);
            $this->addFlash('success', $translator->trans('book.add_success'));

            return $this->redirectToRoute('book_view', [
                'slug' => $book->getSlug(),
            ]);
        }

        return $this->render($this->configuration->getTemplate('Category:create.html.twig'), [
            'form' => $form->createView(),
            'hasManyCategories' => $number >= 5,
            'isBook' => true
        ]);
    }
public function createAction(Request $request)
    {
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
        $manager = $this->getBookManager();

        $book = $manager->createBook($this->getUser());
        $form = $this->createForm(BookType::class, $book);
        $form->handleRequest($request);

        /**@var TranslatorInterface*/
        $translator = $this->get('translator');
        if (($number = $manager->getUserBookNumber($this->getUser())) >= 5) {
            $this->addFlash('danger', $translator->trans('book.more_than_5_books', ['%count%' => $number]));
        }

        if ($form->isSubmitted() && $form->isValid()) {
            $manager->saveBook($book);
            $this->addFlash('success', $translator->trans('book.add_success'));

            return $this->redirectToRoute('book_view', [
                'slug' => $book->getSlug(),
            ]);
        }

        return $this->render($this->configuration->getTemplate('Category:create.html.twig'), [
            'form' => $form->createView(),
            'hasManyCategories' => $number >= 5,
            'isBook' => true
        ]);
    }
创建电子书

@Route("/books/new", name="book_add")

@param Request $request

@return Response