public function editAction() { $this->layout('layout/bags'); $id = $this->params()->fromRoute('id', 0); $ProductTable = $this->getServiceLocator()->get('ProductTable'); $form = new ProductForm(); $form->setInputFilter(new ProductFilter()); // $form->get('news_thumbnail')->removeAttributes(array('required')); $filter = $form->getInputFilter(); // $filter->get('news_thumbnail')->setRequired(false); $data = $this->getServiceLocator()->get('PayoutypeTable')->gettype(); //$form->get('type')->removeAttributes(array('required')); if (is_array($data) and !empty($data)) { $datatypetmp = $data; } else { $datatypetmp = Null; } $form->settype($datatypetmp); $newsDetail = $ProductTable->getById($id); // $this->_fileName = $newsDetail->news_thumbnail; if ($id == 0) { return $this->redirect()->toRoute('Product', array('controller' => 'product', 'action' => 'list-news')); } else { $form->bind($newsDetail); if ($this->getRequest()->isPost()) { $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); $form->setData($data); if (!$form->isValid()) { return new ViewModel(array('error' => true, 'form' => $form, 'id' => $id)); } else { $exchange_data = array(); $exchange_data['id'] = $id; $exchange_data['namepackge'] = $data['namepackge']; $exchange_data['price'] = $data['price']; $exchange_data['id_user'] = $id_user; $exchange_data['type'] = $data['type']; $exchange_data['DKCpmUni'] = $data['DKCpmUni']; $exchange_data['DKCpmRaw'] = $data['DKCpmRaw']; $exchange_data['MBCpmUni'] = $data['MBCpmUni']; $exchange_data['MBCpmRaw'] = $data['MBCpmRaw']; $exchange_data['code'] = $data['code']; $exchange_data['hotstring'] = $data['hotstring']; $Product = new Product(); $Product->exchangeArray($exchange_data); $ProductTable->save($Product); return $this->redirect()->toRoute('Product', array('controller' => 'product', 'action' => 'list-news')); } } return new ViewModel(array('form' => $form, 'id' => $id)); } }