Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('admin/countries', array('action' => 'add'));
     }
     $country = $this->getCountryTable()->getCountry($id);
     $country->setAdapter($this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'));
     $form = new CountryForm();
     $form->bind($country);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Adding already exist validation on runtime excluding the current record
         $country->getInputFilter()->get('country_code')->getValidatorChain()->attach(new \Zend\Validator\Db\NoRecordExists(array('table' => 'country', 'field' => 'country_code', 'adapter' => $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'), 'exclude' => array('field' => 'id', 'value' => $id))));
         $country->getInputFilter()->get('country_name')->getValidatorChain()->attach(new \Zend\Validator\Db\NoRecordExists(array('table' => 'country', 'field' => 'country_name', 'adapter' => $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'), 'exclude' => array('field' => 'id', 'value' => $id))));
         $form->setInputFilter($country->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getCountryTable()->saveCountry($form->getData());
             $this->flashMessenger()->addSuccessMessage('Country updated successfully..!!');
             // Redirect to list of pages
             return $this->redirect()->toRoute('admin/countries');
         } else {
             $this->errors = $form->getMessages();
         }
     }
     return array('id' => $id, 'form' => $form, 'errors' => $this->errors);
 }