12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Routing\Annotation\Route;
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
- class BlogController extends Controller {
- const POSTS = [
- 1 => [
- 'id' => '1',
- 'title' => 'Title 1',
- 'body' => 'Body 1 <3 escaped',
- 'authorName' => 'Fred',
- ],
- 2 => [
- 'id' => '2',
- 'title' => 'Title 2',
- 'body' => 'Body 2',
- 'authorName' => 'Outi',
- ],
- 3 => [
- 'id' => '3',
- 'title' => 'Title 3',
- 'body' => 'Body 3',
- 'authorName' => 'François',
- ],
- ];
- /**
- * @param $page
- *
- * @return Response
- *
- * @Route(
- * name ="blog_list",
- * path ="/blog/{page}",
- * requirements={"page" = "\d+"}
- * )
- */
- public function list($page = 1) {
- return $this->render('blog/index.html.twig', [
- 'blog_entries' => static::POSTS,
- 'pager' => "Page $page of the blog list.",
- ]);
- }
- /**
- * @param $slug
- *
- * @return \Symfony\Component\HttpFoundation\Response
- *
- * @Route(
- * name = "blog_show",
- * path = "/blog/{slug}"
- * )
- */
- public function show($slug) {
- $path = $this->generateUrl('blog_list', [
- // Placeholder: fit in the path.
- 'page' => 2,
- // Non-placeholder: fit in the query
- 'foo' => 'bar',
- ], UrlGeneratorInterface::ABSOLUTE_PATH);
- return new Response("Show $slug. Back to page 2: $path");
- }
- }
|