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
| public function addAction($type)
{
$request = $this->get('request');
$un_media = new Media();
$lisible = ($type == 'livre') ? 1 : 0;
$url = $this->get('router')->generate('_list_auteurs', array(), true);
$em = $this->getDoctrine()->getEntityManager();
$form = $this->createForm(new MediaType(), $un_media,
array('url' => $url,
'em' => $em,
'lisible' => $lisible
)
);
if ('POST' == $request->getMethod()) { // Si on a posté le formulaire
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$un_media = $form->getData();
$em->persist($un_media);
$em->flush();
return new RedirectResponse($this->generateUrl('_welcome'));
}
}
return $this->render('MyBundle:Media:add.html.twig',
array('form' => $form->createView(),
'un_media' => $un_media,
'type' => $type
));
} |