コード例 #1
0
 public function editAction()
 {
     $this->init();
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('pages', array('action' => 'add'));
     }
     $getData = $this->getTable()->getData($id);
     $form = new PagesForm();
     $form->bind($getData);
     //$form->get('submit')->setValue('Edit');
     $form->get('submit')->setAttribute('value', 'Update & Save');
     $request = $this->getRequest();
     //$dbAdapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
     //$form->setDbAdapter($dbAdapter);
     if ($request->isPost()) {
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $pages = new Pages();
         //$dbAdapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
         //$pages->setDbAdapter($dbAdapter);
         $form->setInputFilter($pages->getInputFilter());
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             //echo '<pre>'; print_r($data); exit;
             $isValid = true;
             $thumbnailer = $this->getServiceLocator()->get('WebinoImageThumb');
             $ext_type = array('gif', 'jpg', 'jpe', 'jpeg', 'png');
             if (!empty($data->field_image['name'])) {
                 ErrorHandler::start();
                 $originalFileName = trim($data->field_image['name']);
                 //$ext = end(explode('.',$originalFileName));
                 $efilename = explode('.', $originalFileName);
                 //$ext = $efilename[count($originalFileName) - 1];
                 $ext = end($efilename);
                 //echo $ext; exit();
                 if (!in_array($ext, $ext_type)) {
                     throw new \Exception("Invalid file extenstion - {$ext} ");
                 }
                 $dataArr['field_image'] = $originalFileName;
                 move_uploaded_file($data->field_image['tmp_name'], 'public/upload/' . $data->field_image['name']);
                 $imagePath = 'public/upload/' . $data->field_image['name'];
                 $thumb = $thumbnailer->create($imagePath, $options = array(), $plugins = array());
                 $thumb->resize($this->thumbHeight, $this->thumbWidth);
                 $thumb->save('public/upload/thumb/' . $originalFileName);
                 ErrorHandler::stop(true);
             }
             $dataArr['id'] = $request->getPost('id');
             $dataArr['title'] = $request->getPost('title');
             $dataArr['seo_title'] = $this->seoUrl($request->getPost('title'));
             $dataArr['short_note'] = $request->getPost('short_note');
             $dataArr['content'] = $request->getPost('content');
             $dataArr['modified_on'] = date("Y-m-d H:i:s");
             $dataArr['created_on'] = date("Y-m-d H:i:s");
             $dataArr['active'] = $request->getPost('active');
             $pages->exchangeArray($dataArr);
             $this->getTable()->saveData($pages);
             return $this->redirect()->toRoute('pages', array('action' => 'index'));
         }
     }
     return array('id' => $id, 'form' => $form, 'getData' => $getData);
 }
コード例 #2
0
ファイル: AdminController.php プロジェクト: ponchov/teeforall
 public function savepageAction()
 {
     // set the form to be used in the save page view
     $form = new PagesForm();
     $form->get('add_pages_submit')->setValue('Add New Page');
     // gets the form method request (usually post)
     $request = $this->getRequest();
     // check to see if the request was a POST form request
     if ($request->isPost()) {
         // good to go
         // filter the form values now
         $pages = new Pages();
         $form->setInputFilter($pages->getInputFilter());
         // set the form data to hold all the values supplied by the form
         // via $request->getPost()
         $form->setData($request->getPost());
         // now we will see if the form is valid
         // we check if it is valid by the email form class we created
         if ($form->isValid()) {
             // it is valid
             // pass the form to data to the filter class via exchangeArray()
             $pages->exchangeArray($form->getData());
             $p_id = !empty($this->params('id')) ? $this->params('id') : null;
             if ($this->getPagesService()->savePage($pages) === true) {
                 // the page  was inserted into the database successfully
                 // redirect to pages view
                 return $this->redirect()->toUrl('/admin/pages');
             } else {
                 // error occured..
                 // the error is logged automatically
                 // redirect to pages view
                 return $this->redirect()->toUrl('/admin/pages/' . $p_id);
             }
         }
     }
 }