/**
* Novel controller.
*
* @Route("/novel")
*/
class NovelController extends Controller
{
/**
* Lists all Novel entities.
*
* @Route("/index.html", name="novel")
* @Template()
*/
public function indexAction()
{
$em = $this->getDoctrine()->getEntityManager();
$entities = $em->getRepository('MyFrontendBundle:Novel')->findAll();
return array('entities' => $entities);
}
/**
* Finds and displays a Novel entity.
*
* @Route("/{slug}.html", name="novel_show")
* @Template()
*/
public function showAction($slug)
{
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('MyFrontendBundle:Novel')->findOneBySlug($slug);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Novel entity.');
}
return array('entity' => $entity);
}
}
Listing 34.11. Kontroler Novel
Rozdział 34. Relacje, akcje index i show oraz widoki częściowe