コード例 #1
0
 public function addAction()
 {
     $form = new CategoryForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $category = new Category();
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $category->exchangeArray($form->getData());
             $this->getCategoryTable()->save($category);
             // Redirect to list of category
             return $this->redirect()->toRoute('category');
         }
     }
     return array('form' => $form);
 }
コード例 #2
0
 public function addAction()
 {
     $form = $this->getServiceLocator()->get("Admin\\Form\\CategoryForm");
     if (count($form->getMasterCategoryList()) == 0) {
         return $this->redirect()->toRoute('admin/master_category');
     }
     if (count($form->getSerialNameList()) == 0) {
         return $this->redirect()->toRoute('admin/serial_name');
     }
     if (count($form->getSpecificationList()) == 0) {
         return $this->redirect()->toRoute('admin/specification');
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $category = new Category();
         $form->setInputFilter($category->getInputFilter());
         $data = $request->getPost()->toArray();
         $data['shipping_cost'] = str_replace('.', '', $data['shipping_cost']);
         $data['additional_shipping'] = str_replace('.', '', $data['additional_shipping']);
         $form->setData($data);
         if ($form->isValid()) {
             $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService');
             $fileService->setDestination($this->config['component']['category']['image_path']);
             $fileService->setSize($this->config['file_characteristics']['image']['size']);
             $fileService->setExtension($this->config['file_characteristics']['image']['extension']);
             $image = $fileService->copy($this->params()->fromFiles('image'));
             $data['image'] = $image ? $image : "";
             $category->exchangeArray($data);
             $categoryId = $this->getCategoryTable()->save($category);
             $serialName = $data['serial_name'];
             $specification = $data['specification'];
             $name = $data['name'];
             $this->getCategorySerialNameTable()->save($categoryId, $serialName);
             $this->getCategorySpecificationTable()->save($categoryId, $specification, $name);
             return $this->redirect()->toRoute('admin/category');
         }
     }
     return array('form' => $form, 'config' => $this->config);
 }