Skip to content

Commit

Permalink
Improve routes and fix bug with pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
voronkovich committed Feb 9, 2016
1 parent c3a22f7 commit 9f699de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/AppBundle/Controller/Admin/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function newAction(Request $request)
/**
* Finds and displays a Post entity.
*
* @Route("/{id}", requirements={"id" = "\d+"}, name="admin_post_show")
* @Route("/{id}", requirements={"id": "\d+"}, name="admin_post_show")
* @Method("GET")
*/
public function showAction(Post $post)
Expand All @@ -134,7 +134,7 @@ public function showAction(Post $post)
/**
* Displays a form to edit an existing Post entity.
*
* @Route("/{id}/edit", requirements={"id" = "\d+"}, name="admin_post_edit")
* @Route("/{id}/edit", requirements={"id": "\d+"}, name="admin_post_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Post $post, Request $request)
Expand Down
15 changes: 10 additions & 5 deletions src/AppBundle/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
class BlogController extends Controller
{
/**
* @Route("/", name="blog_index", defaults={"page" = 1})
* @Route("/page/{page}", name="blog_index_paginated", requirements={"page" : "\d+"})
* @Route("/", defaults={"page": 1}, name="blog_index")
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="blog_index_paginated")
* @Method("GET")
* @Cache(smaxage="10")
*/
public function indexAction($page)
Expand All @@ -45,11 +46,16 @@ public function indexAction($page)
$posts = $paginator->paginate($query, $page, Post::NUM_ITEMS);
$posts->setUsedRoute('blog_index_paginated');

if (0 === count($posts)) {
throw $this->createNotFoundException();
}

return $this->render('blog/index.html.twig', array('posts' => $posts));
}

/**
* @Route("/posts/{slug}", name="blog_post")
* @Method("GET")
*
* NOTE: The $post controller argument is automatically injected by Symfony
* after performing a database query looking for a Post with the 'slug'
Expand All @@ -62,10 +68,9 @@ public function postShowAction(Post $post)
}

/**
* @Route("/comment/{postSlug}/new", name = "comment_new")
* @Security("is_granted('IS_AUTHENTICATED_FULLY')")
*
* @Route("/comment/{postSlug}/new", name="comment_new")
* @Method("POST")
* @Security("is_granted('IS_AUTHENTICATED_FULLY')")
* @ParamConverter("post", options={"mapping": {"postSlug": "slug"}})
*
* NOTE: The ParamConverter mapping is required because the route parameter
Expand Down
2 changes: 2 additions & 0 deletions src/AppBundle/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

/**
Expand All @@ -25,6 +26,7 @@ class SecurityController extends Controller
{
/**
* @Route("/login", name="security_login_form")
* @Method("GET")
*/
public function loginAction()
{
Expand Down

0 comments on commit 9f699de

Please sign in to comment.