-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlogController.php
41 lines (32 loc) · 1.06 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
<?php
namespace Peterjmit\BlogBundle\Controller;
use Peterjmit\BlogBundle\Doctrine\BlogRepository;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class BlogController
{
private $repository;
private $templating;
public function __construct(BlogRepository $repository, EngineInterface $templating)
{
$this->repository = $repository;
$this->templating = $templating;
}
public function indexAction()
{
$posts = $this->repository->findAll();
return $this->templating->renderResponse('PeterjmitBlogBundle:Blog:index.html.twig', array(
'posts' => $posts
));
}
public function showAction($id)
{
$post = $this->repository->find($id);
if (!$post) {
throw new NotFoundHttpException(sprintf('Blog post %s was not found', $id));
}
return $this->templating->renderResponse('PeterjmitBlogBundle:Blog:show.html.twig', array(
'post' => $post
));
}
}