1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| /**
* @Route("/profile/edit/friend")
* @Template()
*/
public function friendAction()
{
$userFriend = new UserFriend();
$form = $this->createFormBuilder($userFriend)
->add('friend', 'shtumi_ajax_autocomplete', array('entity_alias' => 'user',
'label' => 'Ajouter un ami : '))
->getForm();
$request = $this->getRequest();
if($request->getMethod() === 'POST')
{
$form->bindRequest($request);
if($form->isValid())
{
$user = $this->get('security.context')->getToken()->getUser();
$userFriend->setUser($user);
if($userFriend->getFriend())
{
$em = $this->getDoctrine()->getEntityManager();
$em->persist($userFriend);
$em->flush();
}
}
}
return array('form' => $form->createView());
} |
Partager