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: ...@@ -13,6 +13,7 @@ imports:
parameters: parameters:
locale: fr locale: fr
avatar_directory: "%kernel.project_dir%/web/assets/img/avatar" avatar_directory: "%kernel.project_dir%/web/assets/img/avatar"
biere_directory: "%kernel.project_dir%/web/assets/img/biere"
framework: framework:
#esi: ~ #esi: ~
......
...@@ -15,7 +15,7 @@ class BiereController extends FOSRestController ...@@ -15,7 +15,7 @@ class BiereController extends FOSRestController
* @param Request $request * @param Request $request
* @Rest\Post(path="/biere") * @Rest\Post(path="/biere")
* @Rest\View() * @Rest\View()
* @return int * @return Biere|\Symfony\Component\Form\FormInterface
*/ */
public function postAction(Request $request) public function postAction(Request $request)
{ {
...@@ -23,7 +23,19 @@ class BiereController extends FOSRestController ...@@ -23,7 +23,19 @@ class BiereController extends FOSRestController
$form = $this->createForm(BiereType::class, $biere); $form = $this->createForm(BiereType::class, $biere);
$form->handleRequest($request); $form->handleRequest($request);
dump($biere); if ($form->isSubmitted() && $form->isValid())
return 0; {
$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