public function addAction(Request $request) { $services = new \Acme\InfoBundle\Entity\Services(); $services->setTitle(''); $services->setDescription(''); $services->setImage(''); $form = $this->createFormBuilder($services)->add('title', 'text')->add('description', 'textarea')->add('image', 'file')->getForm(); $form->handleRequest($request); $validator = $this->get('validator'); $errors = $validator->validate($services); if (count($errors) > 0) { return $this->render('AcmeInfoBundle:Serviceslist:add.html.twig', array('form' => $form->createView())); } else { $a = $request->request->get('form'); $img = $form['image']->getData()->getClientOriginalName(); $services = new Services(); $services->setTitle($a['title']); $services->setDescription($a['description']); $services->setImage($img); $em = $this->getDoctrine()->getManager(); $em->persist($services); $em->flush(); $dir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/recent_works/' . $services->getId(); mkdir($dir); $form->get('image')->getData()->move($dir, $img); return $this->redirect($this->generateUrl('acme_info_serviceslist')); } return $this->render('AcmeInfoBundle:Serviceslist:add.html.twig', array('form' => $form->createView())); }
public function editAction(Request $request) { $id = $request->get('id'); $em = $this->getDoctrine()->getManager(); $service = $em->getRepository('AcmeInfoBundle:Services')->find($id); $oldimg = $service->getImage(); $services = new \Acme\InfoBundle\Entity\Services(); $services->setTitle($service->getTitle()); $services->setDescription($service->getDescription()); $form = $this->createFormBuilder($services)->add('title', 'text')->add('description', 'textarea')->add('image', 'file', array('error_bubbling' => TRUE, 'required' => false))->getForm(); $form->handleRequest($request); $validator = $this->get('validator'); $errors = $validator->validate($services); if ($request->getMethod() == 'POST') { if (count($errors) > 1) { return $this->render('AcmeInfoBundle:Serviceslist:edit.html.twig', array('form' => $form->createView(), 'services' => $services, 'id' => $id, 'image' => $oldimg)); } else { if ($_FILES['form']['name']['image']) { $serv = $em->getRepository('AcmeInfoBundle:Services')->find($id); unlink($_SERVER['DOCUMENT_ROOT'] . '/uploads/recent_works/' . $serv->getId() . '/' . $oldimg); $newimg = $form['image']->getData()->getClientOriginalName(); $serv->setImage($newimg); $em->persist($serv); $em->flush(); $img = $form['image']->getData()->getClientOriginalName(); $dir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/recent_works/' . $serv->getId() . '/'; $form->get('image')->getData()->move($dir, $img); return $this->redirect($this->generateUrl('acme_info_serviceslist')); } else { $a = $request->request->get('form'); $service->setImage($oldimg); $service->setTitle($a['title']); $service->setDescription($a['description']); $em->persist($service); $em->flush(); return $this->redirect($this->generateUrl('acme_info_serviceslist')); } } } return $this->render('AcmeInfoBundle:Serviceslist:edit.html.twig', array('form' => $form->createView(), 'services' => $services, 'id' => $id, 'image' => $oldimg)); }
/** * {@inheritDoc} */ public function getOffset() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getOffset', array()); return parent::getOffset(); }