36
36
class BlogController extends AbstractController
37
37
{
38
38
/**
39
- * @Cache(smaxage="10")
40
- *
41
39
* NOTE: For standard formats, Symfony will also automatically choose the best
42
40
* Content-Type header for the response.
41
+ *
43
42
* See https://symfony.com/doc/current/routing.html#special-parameters
44
43
*/
45
44
#[
46
45
Route('/ ' , defaults: ['page ' => '1 ' , '_format ' => 'html ' ], methods: ['GET ' ], name: 'blog_index ' ),
47
46
Route('/rss.xml ' , defaults: ['page ' => '1 ' , '_format ' => 'xml ' ], methods: ['GET ' ], name: 'blog_rss ' ),
48
47
Route('/page/{page<[1-9]\d*>} ' , defaults: ['_format ' => 'html ' ], methods: ['GET ' ], name: 'blog_index_paginated ' ),
49
48
]
49
+ #[Cache(smaxage: 10 )]
50
50
public function index (Request $ request , int $ page , string $ _format , PostRepository $ posts , TagRepository $ tags ): Response
51
51
{
52
52
$ tag = null ;
@@ -68,6 +68,7 @@ public function index(Request $request, int $page, string $_format, PostReposito
68
68
* NOTE: The $post controller argument is automatically injected by Symfony
69
69
* after performing a database query looking for a Post with the 'slug'
70
70
* value given in the route.
71
+ *
71
72
* See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
72
73
*/
73
74
#[Route('/posts/{slug} ' , methods: ['GET ' ], name: 'blog_post ' )]
@@ -84,14 +85,14 @@ public function postShow(Post $post): Response
84
85
}
85
86
86
87
/**
87
- * @IsGranted("IS_AUTHENTICATED_FULLY")
88
- * @ParamConverter("post", options={"mapping": {"postSlug": "slug"}})
89
- *
90
88
* NOTE: The ParamConverter mapping is required because the route parameter
91
89
* (postSlug) doesn't match any of the Doctrine entity properties (slug).
90
+ *
92
91
* See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html#doctrine-converter
93
92
*/
94
93
#[Route('/comment/{postSlug}/new ' , methods: ['POST ' ], name: 'comment_new ' )]
94
+ #[IsGranted('IS_AUTHENTICATED_FULLY ' )]
95
+ #[ParamConverter('post ' , options: ['mapping ' => ['postSlug ' => 'slug ' ]])]
95
96
public function commentNew (Request $ request , Post $ post , EventDispatcherInterface $ eventDispatcher ): Response
96
97
{
97
98
$ comment = new Comment ();
0 commit comments