src/PHPDish/Bundle/PostBundle/Controller/BookController.php
public function viewChapterAction($slug, $chapterId, Request $request)
    {
        $book = $this->getBookManager()->findBook($slug);
        $chapter = $this->getBookManager()->findChapter($chapterId);
        $chaptersTree = $this->getBookManager()->findBookChaptersTree($book);

        //更新阅读数
        $this->getPostManager()->increasePostViews($chapter);

        //SEO
        $seoPage = $this->get('sonata.seo.page');
        $summary = StringManipulator::stripLineBreak($chapter->getSummary());
        $seoPage
            ->setTitle($chapter->getTitle())
            ->removeMeta('name', 'keywords')
            ->addMeta('name', 'description', $summary)
            ->addMeta('property', 'og:title', $chapter->getTitle())
            ->addMeta('property', 'og:type', 'article')
            ->addMeta('property', 'og:url',  $this->generateUrl('book_read', ['slug' => $slug, 'chapterId' => $chapter->getId()], UrlGeneratorInterface::ABSOLUTE_URL))
            ->addMeta('property', 'og:description', $summary);

        return $this->render($this->configuration->getTemplate('Book:read.html.twig'), [
            'book' => $book,
            'chapter' => $chapter,
            'chaptersTree' => $chaptersTree
        ]);
    }
public function viewChapterAction($slug, $chapterId, Request $request)
    {
        $book = $this->getBookManager()->findBook($slug);
        $chapter = $this->getBookManager()->findChapter($chapterId);
        $chaptersTree = $this->getBookManager()->findBookChaptersTree($book);

        //更新阅读数
        $this->getPostManager()->increasePostViews($chapter);

        //SEO
        $seoPage = $this->get('sonata.seo.page');
        $summary = StringManipulator::stripLineBreak($chapter->getSummary());
        $seoPage
            ->setTitle($chapter->getTitle())
            ->removeMeta('name', 'keywords')
            ->addMeta('name', 'description', $summary)
            ->addMeta('property', 'og:title', $chapter->getTitle())
            ->addMeta('property', 'og:type', 'article')
            ->addMeta('property', 'og:url',  $this->generateUrl('book_read', ['slug' => $slug, 'chapterId' => $chapter->getId()], UrlGeneratorInterface::ABSOLUTE_URL))
            ->addMeta('property', 'og:description', $summary);

        return $this->render($this->configuration->getTemplate('Book:read.html.twig'), [
            'book' => $book,
            'chapter' => $chapter,
            'chaptersTree' => $chaptersTree
        ]);
    }
查看电子书具体章节

@Route("/books/{slug}/chapters/{chapterId}", name="book_read", requirements={"slug": "[\w-]+", "chapterId": "\d+"})
@param string $slug
@param int $chapterId
@param Request $request
@return Response