|
34 | 34 | class BlogController extends Controller
|
35 | 35 | {
|
36 | 36 | /**
|
37 |
| - * @Route("/", defaults={"page": "1"}, name="blog_index") |
38 |
| - * @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="blog_index_paginated") |
| 37 | + * @Route("/", defaults={"page": "1", "_format"="html"}, name="blog_index") |
| 38 | + * @Route("/rss.xml", defaults={"page": "1", "_format"="xml"}, name="blog_rss") |
| 39 | + * @Route("/page/{page}", defaults={"_format"="html"}, requirements={"page": "[1-9]\d*"}, name="blog_index_paginated") |
39 | 40 | * @Method("GET")
|
40 | 41 | * @Cache(smaxage="10")
|
| 42 | + * |
| 43 | + * NOTE: For standard formats, Symfony will also automatically choose the best |
| 44 | + * Content-Type header for the response. |
| 45 | + * See http://symfony.com/doc/current/quick_tour/the_controller.html#using-formats |
41 | 46 | */
|
42 |
| - public function indexAction($page) |
| 47 | + public function indexAction($page, $_format) |
43 | 48 | {
|
44 | 49 | $posts = $this->getDoctrine()->getRepository(Post::class)->findLatest($page);
|
45 | 50 |
|
46 |
| - return $this->render('blog/index.html.twig', ['posts' => $posts]); |
| 51 | + // Every template name also has two extensions that specify the format and |
| 52 | + // engine for that template. |
| 53 | + // See https://symfony.com/doc/current/templating.html#template-suffix |
| 54 | + return $this->render('blog/index.'.$_format.'.twig', ['posts' => $posts]); |
47 | 55 | }
|
48 | 56 |
|
49 | 57 | /**
|
|
0 commit comments