public function editAction() { $data = $this->getRequest()->getPost('data'); $submit = $this->getRequest()->getPost('submit'); $id = $this->_getParam('id'); $langFilter = $this->_getParam('langFilter'); //check if cancel button is pressed if ($this->_formHelper->isCancel()) { //cancel form return $this->_formHelper->returnCancel($this->view->url(array('action' => 'index')), $this->translate('Action canceled')); } //create form object $form = new Translation_Form_Type($data); //postback - save? if ($this->_formHelper->isSave()) { //check if valid if ($form->isValid()) { $values = $form->getValues(); //create entity object from submitted values, and save $type = new Translation_Model_Type($values); Translation_Model_TypeMapper::getInstance()->save($type); //save done, return success return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'index')), $this->translate('Type saved.')); } else { //we have errors - return json or continue $this->_formHelper->returnError($form->getMessages()); } } elseif (!$this->_formHelper->getRequest()->isPost()) { //edit action if (isset($id) && $id > 0) { $type = new Translation_Model_Type(); if (!Translation_Model_TypeMapper::getInstance()->find($id, $type)) { throw new Exception("Type not found"); } //fetch data $data = $type->toArray(); //populate form with data $form->setData($data); } } $this->view->data = $data; }