public function addAction(Request $request) { $work = new \Acme\InfoBundle\Entity\Work(); $work->setTitle(''); $work->setDescription(''); $work->setImage(''); $form = $this->createFormBuilder($work)->add('title', 'text')->add('description', 'textarea')->add('image', 'file')->getForm(); $form->handleRequest($request); $validator = $this->get('validator'); $errors = $validator->validate($work); if (count($errors) > 0) { return $this->render('AcmeInfoBundle:Work:add.html.twig', array('form' => $form->createView())); } else { $a = $request->request->get('form'); $img = $form['image']->getData()->getClientOriginalName(); $work = new Work(); $work->setTitle($a['title']); $work->setDescription($a['description']); $work->setImage($img); $em = $this->getDoctrine()->getManager(); $em->persist($work); $em->flush(); $dir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/works/' . $work->getId(); mkdir($dir); $form->get('image')->getData()->move($dir, $img); return $this->redirect($this->generateUrl('acme_info_work')); } return $this->render('AcmeInfoBundle:Work:add.html.twig', array('form' => $form->createView())); }
/** * {@inheritDoc} */ public function setImage($image) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setImage', array($image)); return parent::setImage($image); }