diff --git a/0ne/orig/ajax/index4.html b/0ne/orig/ajax/index4.html new file mode 100644 index 0000000000000000000000000000000000000000..4420c7b428599eb6fc64001512a5f3f65aef5380 --- /dev/null +++ b/0ne/orig/ajax/index4.html @@ -0,0 +1,93 @@ + + + + + Title + + + + + +
+ Nom
+ Adresse
+ Pays
+ +
+ + + + diff --git a/src/Api2Bundle/Controller/BrasserieController.php b/src/Api2Bundle/Controller/BrasserieController.php index 16b34be2ef8f8adc44fe5e0d1a7e33244c19e6c1..eb972d77f66ab312fa8186a7de371c66dee13727 100755 --- a/src/Api2Bundle/Controller/BrasserieController.php +++ b/src/Api2Bundle/Controller/BrasserieController.php @@ -25,21 +25,63 @@ class BrasserieController extends FOSRestController /** * @param Request $request - * @param $id + * @param Brasserie $id * @Rest\Put(path="/brasserie/{id}") * @Rest\View() + * @return Brasserie */ public function putAction(Request $request, Brasserie $id) { // le fait de typer $id fait qu'il retourne un objet ! - $form = $this->createForm(BrasserieType::class, $id); + $form = $this->createForm(BrasserieType::class, $id, + array( + 'method' => 'put' + ) + ); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - dump($form); die; + $em = $this->getDoctrine()->getManager(); + $em->flush(); + return $id; } - dump('form invalide'); die; + return $form; + } + + + /** + * @param Brasserie $id + * @Rest\Get(path="/brasserie/{id}") + * @Rest\View() + * @return Brasserie + */ + public function getByIdAction(Brasserie $id) + { + return $id; + } + + + /** + * @param Request $request + * @Rest\Post(path="/brasserie") + * @Rest\View() + * @return Brasserie + */ + public function newAction(Request $request) + { + $brasserie = new Brasserie(); + $form = $this->createForm(BrasserieType::class, $brasserie); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) + { + $em = $this->getDoctrine()->getManager(); + $em->persist($brasserie); + $em->flush(); + return $brasserie; + } + return $form; } } diff --git a/src/Api2Bundle/Form/BrasserieType.php b/src/Api2Bundle/Form/BrasserieType.php index b26ddcfd14f6ed793ae1c1772903fc841bc749c9..c20e35e40fe8254728d205507b438328878b7dbb 100755 --- a/src/Api2Bundle/Form/BrasserieType.php +++ b/src/Api2Bundle/Form/BrasserieType.php @@ -25,7 +25,8 @@ class BrasserieType extends AbstractType public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( - 'data_class' => 'Api2Bundle\Entity\Brasserie' + 'data_class' => 'Api2Bundle\Entity\Brasserie', + 'csrf_protection' => false )); }