示例#1
0
 public function addAction()
 {
     $form = new BrandForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $brand = new Brand();
         $form->setInputFilter($brand->getInputFilter());
         $data = $request->getPost()->toArray();
         $form->setData($data);
         if ($form->isValid()) {
             $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService');
             $fileService->setDestination($this->config['component']['brand']['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'));
             $backgroundImage = $fileService->copy($this->params()->fromFiles('background_image'));
             $data['image'] = $image ? $image : "";
             $data['background_image'] = $backgroundImage ? $backgroundImage : "";
             $brand->exchangeArray($data);
             $this->getBrandTable()->save($brand);
             return $this->redirect()->toRoute('admin/brand');
         }
     }
     return array('form' => $form, 'config' => $this->config);
 }