public function addAction() { if ($this->getRequest()->isPost()) { $formdata = $this->getRequest()->getPost(); $model = new Application_Model_Product($formdata); $objMapper = new Application_Model_ProductMapper($model); $pro_id = $objMapper->save($model); if (is_numeric($pro_id)) { $err = "record saved"; } } $this->view; }
public function saveAction() { $request = $this->getRequest(); $id = $this->getParam('id'); $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $user_id = $auth->getIdentity()->id; } $form = $this->getSaveProductForm($id); if ($this->getRequest()->isPost()) { if ($form->isValid($request->getPost())) { $data = $this->getRequest()->getParams(); $upload = new Zend_File_Transfer(); $files = $upload->getFileInfo(); $isValid = true; foreach ($files as $field => $file) { if (!strlen($file["name"])) { continue; } $extension = pathinfo($file['name'], PATHINFO_EXTENSION); $filename = pathinfo($file['name'], PATHINFO_FILENAME); if (!file_exists(UPLOADS_IMAGES)) { mkdir(UPLOADS_IMAGES, 0774, true); } if (!file_exists(UPLOADS_DATA)) { mkdir(UPLOADS_DATA, 0774, true); } // upload instructions for image if ($field == 'image') { $upload->addFilter('Rename', array('target' => UPLOADS_IMAGES . '/' . $filename . "_" . $user_id . "_" . time() . "." . $extension, 'overwrite' => TRUE), $field)->addValidator('Extension', false, array('jpg', 'jpeg', 'png'), $field); $data['image'] = $filename . "_" . $user_id . "_" . time() . "." . $extension; } // upload instructions for file if ($field == 'file') { $upload->addFilter('Rename', array('target' => UPLOADS_DATA . '/' . $filename . "_" . $user_id . "_" . time() . "." . $extension, 'overwrite' => TRUE), $field)->addValidator('Extension', false, array('doc', 'docx', 'txt', 'pdf'), $field); $data['file'] = $filename . "_" . $user_id . "_" . time() . "." . $extension; } if ($upload->isValid($field)) { if (!$upload->receive($field)) { $isValid = false; foreach ($upload->getMessages() as $key => $val) { $this->_helper->getHelper('FlashMessenger')->addMessage($val, 'error'); } } } else { $isValid = false; $this->_helper->getHelper('FlashMessenger')->addMessage($file['name'] . " is not valid {$field}", 'error'); //return $this->_helper->redirector('save'); } } if ($upload->hasErrors()) { $errors = $upload->getMessages(); foreach ($errors as $error) { $this->_helper->getHelper('FlashMessenger')->addMessage("{$error}", 'error'); } return $this->_helper->redirector('save'); } if ($isValid) { $product = new Application_Model_Product(); $productMapper = new Application_Model_ProductMapper(); if ($id) { $product = $productMapper->getProductById($id); } if (isset($data['file']) && $product->file && $product->file != $data['file'] || !isset($data['file']) && $product->file) { $productMapper->delete_file($product->file); } if (isset($data['image']) && $product->image && $product->image != $data['image'] || !isset($data['image']) && $product->image) { $productMapper->delete_image($product->image); } $product = new Application_Model_Product($data); $productMapper->save($product); return $this->_helper->redirector('dashboard', 'users'); } } } $this->view->headScript()->appendFile(JS_DIR . '/' . self::DELETE_FIELD . '.js'); $this->view->form = $form; }