public function editAction() { $utility = new Utility(); $Slider = new Slider(); $view = new ViewModel(); $id = (int) $this->params()->fromRoute('id', 0); $getcata = $this->getSliderTable()->getSlider($id); $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); $getuser = $this->forward()->dispatch('Admin\\Controller\\Index', array('action' => 'getuser')); $this->layout()->getuser = $getuser; if ($getuser && ($getuser->group == 'admin' || $getuser->group == 'supperadmin')) { $this->layout('layout/bags'); $form = new SliderForm($dbAdapter); $form->setInputFilter(new SliderFormFilter()); $Sliderarr = $this->getdataAction(); $form->setId($Sliderarr); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($Slider->getInputFilter()); // check validate $data = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); // print_r($data); //die; $form->setData($data); if ($form->isValid()) { if ($data['img']['name'] != '') { // edit anh $_array_img = $data['img']; // Recyle Bin img older $get_img_older = $getcata->img; $_dir = UPLOAD_PATH_IMG; if ($get_img_older) { $dir = ROOT_PATH . '/public/imgslideshow'; $utility->deleteSlideshow($get_img_older, $dir); // delete img older thumb_slideshow $dir_thumb = ROOT_PATH . '/public/imgslideshow/thumb_slideshow'; $utility->deleteSlideshow($get_img_older, $dir_thumb); // delete img older thumb_slideshow2 $dir_thumb_2 = ROOT_PATH . '/public/imgslideshow/thumb_slideshow2'; $utility->deleteSlideshow($get_img_older, $dir_thumb_2); } // upload and rename $renname_file_img = $utility->uploadImageSlideshow($_array_img); if (!$renname_file_img) { $view->check = 0; return $view; } $Slider = new Slider(); $Slider->dataArraySwap($data, $renname_file_img); $check = $this->getSliderTable()->saveSlider($Slider); $view->check = $check; return $view; } else { $id = $data['id']; $getcata = $this->getSliderTable()->getSlider($id); if ($getcata) { $get_img_older = $getcata->img; } $Slider = new Slider(); $Slider->dataArraySwap($form->getData(), $get_img_older); $check = $this->getSliderTable()->saveSlider($Slider); $_url = WEBPATH . '/catalog/edit/' . $id; if ($check == 0) { $this->redirect()->toUrl($_url); } // $view->check = $check; // return $view; } } else { $messages = $form->getMessages(); } } $form->setId($Sliderarr); $Slider_id = (int) $this->params()->fromRoute('id', 0); $Slider_cr = $this->getSliderTable()->getSlider($Slider_id); if ($Slider_cr) { $form->bind($Slider_cr); $_img_thumb = $Slider_cr->img; } $view->setVariable('img_thumb', $_img_thumb); //$form->get ( 'submit' )->setAttribute ( 'value', 'Edit Slider' ); if ($Slider_id == 0) { $form->get('submit')->setAttribute('value', 'Add Slider'); } else { $form->get('submit')->setAttribute('value', 'Edit Slider'); $view->setVariable('error', 1); } $view->setVariable('Sliderform', $form); return $view; } else { $view->check = 2; $this->layout('error/admin'); } }