Skip to content

Instantly share code, notes, and snippets.

@monofone
Created April 17, 2014 00:15
Show Gist options
  • Save monofone/10944067 to your computer and use it in GitHub Desktop.
Save monofone/10944067 to your computer and use it in GitHub Desktop.
<?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