Exemple #1
0
 /**
  * View blog post
  *
  * @Route(
  *      path = "/{id}/{slug}",
  *      name = "store_blog_post_view",
  *      methods = {"GET"}
  * )
  *
  * @AnnotationEntity(
  *      class = "elcodi.entity.page.class",
  *      name = "blogPost",
  *      mapping = {
  *          "id" = "~id~",
  *          "enabled" = true,
  *      }
  * )
  */
 public function viewBlogPostAction(PageInterface $blogPost, $slug)
 {
     if (ElcodiPageTypes::TYPE_BLOG_POST !== $blogPost->getType()) {
         $this->createNotFoundException();
     }
     /**
      * We must check that the product slug is right. Otherwise we must
      * return a Redirection 301 to the right url
      */
     if ($slug !== $blogPost->getPath()) {
         return $this->redirectToRoute('store_blog_post_view', ['id' => $blogPost->getId(), 'slug' => $blogPost->getPath()]);
     }
     return $this->renderTemplate('Pages:blog-post-view.html.twig', ['blog_post' => $blogPost]);
 }
 /**
  * Render a page given the found instance
  *
  * @param PageInterface|null $page Found page
  * @param string             $path Page route path
  *
  * @return Response Page rendered
  *
  * @throws RuntimeException      Request object not found
  * @throws NotFoundHttpException Page not found or not valid
  */
 public function createResponseFromPage(PageInterface $page = null, $path = '')
 {
     if (!$page instanceof PageInterface || $page->getType() !== ElcodiPageTypes::TYPE_REGULAR) {
         throw new NotFoundHttpException('Page not found');
     }
     $request = $this->requestStack->getCurrentRequest();
     /**
      * Request not found because this controller is not running under
      * Request scope
      */
     if (!$request instanceof Request) {
         throw new RuntimeException('Request object not found');
     }
     /**
      * We must check that the product slug is right. Otherwise we must
      * return a Redirection 301 to the right url
      */
     if ($page->getPath() && $path !== $page->getPath()) {
         return new RedirectResponse($this->urlGenerator->generate($this->pageRenderRoute, ['id' => $page->getId(), 'path' => $page->getPath()]), 301);
     }
     $response = $this->createResponseInstance($page);
     if (!$response->isNotModified($request)) {
         $response->setContent($this->renderPage($page));
         $response->headers->set('Content-Type', 'text/html');
     }
     return $response;
 }