Commit 2929163c authored by Mat's avatar Mat

termine le controller pour sauvegarder la bière, et son image

parent 07a496b9
......@@ -13,6 +13,7 @@ imports:
parameters:
locale: fr
avatar_directory: "%kernel.project_dir%/web/assets/img/avatar"
biere_directory: "%kernel.project_dir%/web/assets/img/biere"
framework:
#esi: ~
......
......@@ -15,7 +15,7 @@ class BiereController extends FOSRestController
* @param Request $request
* @Rest\Post(path="/biere")
* @Rest\View()
* @return int
* @return Biere|\Symfony\Component\Form\FormInterface
*/
public function postAction(Request $request)
{
......@@ -23,7 +23,19 @@ class BiereController extends FOSRestController
$form = $this->createForm(BiereType::class, $biere);
$form->handleRequest($request);
dump($biere);
return 0;
if ($form->isSubmitted() && $form->isValid())
{
$file = $biere->getFile();
$uniquePath = md5(uniqid()). '_' . $file->getClientOriginalName();
$file->move($this->getParameter('biere_directory'), $uniquePath);
$biere->setImage($uniquePath);
$em = $this->getDoctrine()->getManager();
$em->persist($biere);
$em->flush();
return $biere;
}
return $form;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment