Created
April 17, 2014 00:15
-
-
Save monofone/10944067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Blage\BlogBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |
class DefaultController extends Controller | |
{ | |
/** | |
* @Route("/") | |
* @Template() | |
*/ | |
public function indexAction() | |
{ | |
$articles = $this->getDoctrine() | |
->getRepository('BlageBlogBundle:Article') | |
->findLatest(); | |
return array('articles'=>$articles); | |
} | |
/** | |
* @Route("/article/{year}/{month}/{slug}") | |
* @Template() | |
*/ | |
public function articleAction($year, $month, $slug) | |
{ | |
$article = $this->getDoctrine() | |
->getRepository('BlageBlogBundle:Article') | |
->findOneBy(array( | |
'slug' => $slug, | |
'online' => true | |
)); | |
if(!$article){ | |
throw new NotFoundHttpException(sprintf("article with slug %s not found", $slug)); | |
} | |
return array('article' => $article); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment