public function countryeditAction() { $this->_checkIfUserIsLoggedIn(); $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('admin/default', array('controller' => 'geography', 'action' => 'countryadd')); } $country = $this->getEntityManager()->find('Admin\\Entity\\Country', $id); // print_r($city);die; if (!$country) { return $this->redirect()->toRoute('admin/default', array('controller' => 'geography', 'action' => 'country')); } $em = $this->getEntityManager(); $form = new CountryForm($em); $tempcountry = $country->contryphoto; $form->bind($country); $form->get('save')->setAttribute('value', 'Edit'); $form->getInputFilter()->get('contryphoto')->setRequired(false); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($country->getInputFilter()); $data = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $form->setData($data); if ($form->isValid()) { $filname = $data['contryphoto']['name']; if ($filname == "") { $filname = $tempcountry; } $extension = pathinfo($filname, PATHINFO_EXTENSION); $cntryName = str_replace(" ", "-", $data['cntryName']) . $id . "." . $extension; $country->setcountryPhoto($cntryName); $adapter = new \Zend\File\Transfer\Adapter\Http(); $adapter->setDestination('public/images/country'); $adapter->addFilter('Rename', $cntryName, $filname); $adapter->receive($filname); $this->getEntityManager()->flush(); return $this->redirect()->toRoute('admin/default', array('controller' => 'geography', 'action' => 'country')); } } return array('id' => $id, 'form' => $form); }