Skip to content

Instantly share code, notes, and snippets.

@afiocre
Last active August 29, 2015 13:58
Show Gist options
  • Save afiocre/10141439 to your computer and use it in GitHub Desktop.
Save afiocre/10141439 to your computer and use it in GitHub Desktop.

##Chargement automatique d'un objet dans une action de controleur

Avant

/**
 * @Route("/{id}/edit", name="route_edit")
 */
public function editAction($id)
{
  $em = $this->getDoctrine()->getManager();
  $establishment = $em->getRepository('HeadooCoreBundle:Establishment')->find($id);
}

Après

/**
 * @Route("/{id}/edit", name="route_edit")
 */
public function editAction(Establishment $establishment)
{
}

##Chargement de l'utilisateur connecté depuis un contrôleur

Avant

$user = $this->get('security.context')->getToken()->getUser();

Après

$user = $this->getUser();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment