public function addAction()
 {
     $renderer = $this->serviceLocator->get('Zend\\View\\Renderer\\RendererInterface');
     //echo  $renderer->basePath();
     //exit;
     $this->init();
     $this->appendMyJs();
     $form = new AdvertisementForm();
     $form->get('submit')->setValue('Submit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Make certain to merge the files info!
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $advertise = new Advertisement();
         $form->setInputFilter($advertise->getInputFilter());
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             $isValid = true;
             $thumbnailer = $this->getServiceLocator()->get('WebinoImageThumb');
             //echo $_SERVER['DOCUMENT_ROOT'];
             //exit;
             if (!empty($data['image_1'])) {
                 ErrorHandler::start();
                 $originalFileName = trim($data['image_1']['name']);
                 $dataArr['image_1'] = $this->rootDomain . $renderer->basePath() . '/upload/thumb/' . $originalFileName;
                 move_uploaded_file($data['image_1']['tmp_name'], $this->filePath . $data['image_1']['name']);
                 $imagePath = $this->filePath . $data['image_1']['name'];
                 $thumb = $thumbnailer->create($imagePath, $options = array(), $plugins = array());
                 $thumb->resize($this->thumbHeight, $this->thumbWidth);
                 $thumb->save($this->filePath . 'thumb/' . $originalFileName);
                 ErrorHandler::stop(true);
             }
             if (!empty($data['image_2'])) {
                 ErrorHandler::start();
                 $originalFileName2 = trim($data['image_2']['name']);
                 $dataArr['image_2'] = $this->rootDomain . $renderer->basePath() . '/upload/thumb/' . $originalFileName2;
                 move_uploaded_file($data['image_2']['tmp_name'], $this->filePath . $data['image_2']['name']);
                 $imagePath = $this->filePath . $data['image_2']['name'];
                 $thumb = $thumbnailer->create($imagePath, $options = array(), $plugins = array());
                 $thumb->resize($this->thumbHeight, $this->thumbWidth);
                 $thumb->save($this->filePath . 'thumb/' . $originalFileName2);
                 ErrorHandler::stop(true);
             }
             $dataArr['advertisement_type_id'] = $request->getPost('advertisement_type_id');
             $dataArr['duration'] = $request->getPost('duration');
             $dataArr['modified_on'] = time();
             $dataArr['created_on'] = time();
             $dataArr['active'] = $request->getPost('active');
             $dataArr['notification'] = 0;
             $dataArr['content'] = $request->getPost('content');
             $dataArr['url'] = $request->getPost('url');
             $advertise->exchangeArray($dataArr);
             $this->getTable()->saveData($advertise);
             return $this->redirect()->toRoute('advertisement', array('action' => 'index'));
         }
     }
     return array('form' => $form, 'flashMessages' => $this->flashmessenger()->getMessages());
 }
 public function addAction()
 {
     $form = new AdvertisementForm($this->getServiceLocator()->get('Admin\\Model\\StatusTable'));
     //$form = new AdvertisementForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $advertisement = new Advertisement();
         $form->setInputFilter($advertisement->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $advertisement->exchangeArray($form->getData());
             $this->getAdvertisementTable()->saveAdvertisement($advertisement);
             $this->flashMessenger()->addSuccessMessage('Advertisement added successfully..!!');
             // Redirect to list of pages
             return $this->redirect()->toRoute('admin/advertisement');
         } else {
             $this->errors = $form->getMessages();
         }
     }
     return array('form' => $form, 'errors' => $this->errors);
 }