Skip to content

Instantly share code, notes, and snippets.

@NandoKstroNet
Created May 24, 2017 17:47
Show Gist options
  • Save NandoKstroNet/a4d0e41f458636c4a5da579a5b8cd33c to your computer and use it in GitHub Desktop.
Save NandoKstroNet/a4d0e41f458636c4a5da579a5b8cd33c to your computer and use it in GitHub Desktop.
Controller Posts - Série de Posts da Code Experts Learning no Medium sobre Symfony
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Post;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* @Route("/posts")
*/
class PostController extends Controller
{
/**
* @Route("/", name="index_post")
*/
public function indexAction()
{
$posts = $this->getDoctrine()->getRepository('AppBundle:Post')
->findAll();
return $this->render('posts/index.html.twig', array('posts' => $posts));
}
/**
* @Route("/view/{slug}", name="view_post")
*/
public function viewAction($slug)
{
$post = $this->getDoctrine()->getRepository('AppBundle:Post')->findOneBySlug($slug);
return $this->render('posts/single.html.twig', array('post' => $post));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment