przewiń do treści

Symfony 2 od podstaw

Włodzimierz Gajda

/**
 * @Route("/{slug}.html", name="song_show")
 * @Template()
 */
public function showAction($slug)
{
    $em = $this->getDoctrine()->getEntityManager();
    $entity = $em->getRepository('MyFrontendBundle:Song')->findOneBySlug($slug);

    if (!$entity) {
        throw $this->createNotFoundException('Podana strona nie istnieje!');
    }

    return array('entity' => $entity);
}

Listing 27.2. Kod akcji show

Rozdział 27. Identyfikacja rekordu na podstawie wartości slug

listing-27-02.txt

Reklama

Szkolenia z Symfony 2.1
©2012 Włodzimierz Gajda
ver. 1.0.1