/** * @Security("has_role('ROLE_SUPER_ADMIN')") * @Route("/test", name="testNewForm") */ public function newTestFormAction(Request $request) { $image = new Image(); $form = $this->createFormBuilder($image)->add('file', 'file', array('label' => 'Изображение:'))->getForm(); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $test = new Test(); $test->setName($request->get('_name')); $test->setDescription($request->get('_description')); $company = $this->getDoctrine()->getRepository('AppBundle:Company')->find($request->get('_company')); $test->addCompany($company); $company->addTest($test); if (!$form->get('file')->isEmpty()) { $test->setImage($image); $em->persist($test); $em->flush(); $image->upload($test->getId()); $image->setPath($test->getId() . '/' . $form->get('file')->getData()->getClientOriginalName()); $em->persist($image); $em->flush(); return $this->redirectToRoute('aboutTestpage', array('id' => $test->getId())); } $em->persist($test); $em->flush(); return $this->redirectToRoute('aboutTestpage', array('id' => $test->getId())); } return $this->render(':tests:new_test.html.twig', array('companies' => $this->getDoctrine()->getRepository('AppBundle:Company')->findAll(), 'uploadForm' => $form->createView())); }