public function editAction() { $session = new Container('admin'); if (!$session->offsetExists('email')) { $this->redirect()->toRoute('admin', array('action' => 'login'), array('query' => array('status' => 'u_login'))); } $form = new CountryForm(); $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('country', array('action' => 'add')); } try { $country = $this->getCountryTable()->getCountry($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('country', array('action' => 'index')); } $form->bind($country); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($country->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->getCountryTable()->saveCountry($country); return $this->redirect()->toRoute('country'); } } return array('id' => $id, 'form' => $form); }
public function addAction() { $form = new CountryForm(); $form->get('submit')->setValue('Add'); // CSS $form->get('name')->setAttribute('class', 'form-control'); $form->get('name')->setAttribute('placeholder', 'Ej.: Francia'); $request = $this->getRequest(); if ($request->isPost()) { $country = new Country(); $form->setInputFilter($country->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $country->exchangeArray($form->getData()); $this->getEntityManager()->persist($country); $this->getEntityManager()->flush(); // Redirect to Country List return $this->redirect()->toRoute('country'); } } return array('form' => $form); }