Created
May 24, 2017 17:47
-
-
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
This file contains hidden or 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 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