/
BlogController.php
50 lines (43 loc) · 1.17 KB
/
BlogController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use JMS\DiExtraBundle\Annotation as DI;
use AppBundle\Service\BlogService;
use AppBundle\Entity\BlogArticle;
class BlogController extends Controller
{
private $service;
/**
* @DI\InjectParams({
* "service" = @DI\Inject("app.blog_service")
* })
*/
public function __construct(BlogService $service)
{
$this->service = $service;
}
/**
* @Route("/")
*/
public function indexAction()
{
$blogs = $this->service->getAllPosts();
return $this->render('Blog/index.html.twig', [
'blogs' => $blogs
]);
}
/**
* @Route("/show/{id}", name="blog_show")
* @ParamConverter("blog", class="AppBundle:BlogArticle")
* @Method("get")
*/
public function showAction(BlogArticle $blog)
{
return $this->render('Blog/show.html.twig', [
'blog' => $blog
]);
}
}