public function editAction() { if ($this->zfcUserAuthentication()->hasIdentity() && $this->zfcUserAuthentication()->getIdentity()->getRole() == "admin") { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('product', array('action' => 'add')); } $product = $this->getProductTable()->getProduct($id); $form = new ProductForm(); $form->bind($product); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($product->getInputFilter()); $form->setData(array_merge($request->getPost()->toArray(), $request->getFiles()->toArray())); if ($form->isValid()) { $fileName = $form->getData()['image']['name']; if (move_uploaded_file($form->getData()['image']['tmp_name'], getcwd() . '/public/img/' . $fileName)) { echo "Файл корректен и был успешно загружен.\n"; } else { echo "Возможная атака с помощью файловой загрузки!\n"; } $product->exchangeArray($form->getData()); $this->getProductTable()->saveProduct($form->getData()); // Redirect to list of products return $this->redirect()->toRoute('product'); } } return array('id' => $id, 'form' => $form); } else { $view = new ViewModel(array('message' => 'GET OUT OF HERE!')); $view->setTemplate('product/error/access'); return $view; } }
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)); } }
public function addAction() { $form = new ProductForm(); $product = new Product(); $form->bind($product); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $objectManager->persist($product); $objectManager->flush(); return $this->redirect()->toRoute('product'); } } return array('form' => $form); }
public function editAction() { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('product', array('action' => 'add')); } // Get the Product with the specified id. An exception is thrown // if it cannot be found, in which case go to the index page. try { $product = $this->getProductTable()->getProduct($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('product', array('action' => 'index')); } if (!$product) { return $this->redirect()->toRoute('product', array('action' => 'add')); } // var_dump($product); $form = new ProductForm(); $form->bind($product); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($product->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->getProductTable()->saveProduct($product); // Redirect to list of products return $this->redirect()->toRoute('product'); } } return array('id' => $id, 'form' => $form, 'shops' => $this->getShopTable()->fetchAll($this->getServiceLocator()->get('AuthService')->getStorage()->read()->id), 'product_categories' => $this->getProductCategoryTable()->fetchAll($this->getServiceLocator()->get('AuthService')->getStorage()->read()->id)); }
public function editAction() { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('product', array('action' => 'add')); } try { $product = $this->getProductTable()->getProduct($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('product', array('action' => 'index')); } $form = new ProductForm(); $form->bind($product); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($product->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->getProductTable()->saveProduct($product); return $this->redirect()->toRoute('product'); } } return array('id' => $id, 'form' => $form); }
public function editAction() { $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_another'); $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('product', array('action' => 'create')); } try { $product = $em->getRepository("Product\\Entity\\Product")->find($id); $productModel = new \Product\Model\Product(); $productModel->exchangeProductEntity($product); $oldFileName = $product->getImage(); $tag = new Tags(); foreach ($product->getIdTag() as $tag) { $tagArrayName[] = $tag->getName(); } } catch (\Exception $ex) { return $this->redirect()->toRoute('product', array('action' => 'list')); } $form = new ProductForm(); $form->bind($productModel); $form->get('tags')->setValue(implode(",", $tagArrayName)); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($productModel->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $File = $this->params()->fromFiles('image'); $product->exchangeArray($request->getPost()); $adapter = new \Zend\File\Transfer\Adapter\Http(); $this->deleteImage($oldFileName); $this->saveImage($form, $adapter, $File); $product->setImage($adapter->getFileName(null, false)); foreach ($product->getIdTag() as $tag) { $em->remove($tag); } $tagsArray = explode(",", $form->get("tags")->getValue()); foreach ($tagsArray as $tag) { $entityTag = new Tags(); $entityTag->setName($tag); $product->getIdTag()->add($entityTag); $em->persist($entityTag); } $em->persist($product); $em->flush(); return $this->redirect()->toRoute('product'); } } return array('id' => $id, 'form' => $form); }