public function editAction($id) { $id = (int) $id; $form = new SliderForm(); $model = Slider::findFirst(array("id = {$id}")); if ($this->request->isPost()) { $form->bind($this->request->getPost(), $model); if ($form->isValid()) { $this->uploadImages($model->getId(), 'slider'); if ($model->save()) { $this->flash->success('Информация обновлена'); return $this->redirect('/slider/admin/edit/' . $model->getId()); } else { $this->flash->error('Информация не сохранена!'); $this->flashErrors($model); } } else { $this->flashErrors($form); } } else { $form->setEntity($model); } $this->view->setVars(array('form' => $form, 'model' => $model, 'title' => 'Редактирование слайдера')); }
public function mastereditAction() { $utility = new Utility(); $Slider = new Slider(); $view = new ViewModel(); $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/apotravinyadmin'); $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 $id = $data['id']; $getcata = $this->getSliderTable()->getSlider($id); $get_img_older = $getcata->img; $_dir = UPLOAD_PATH_IMG; if ($get_img_older) { $utility->deleteImage($get_img_older, $_dir); } // upload and rename $renname_file_img = $utility->uploadImageAlatca($_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; } } } $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); } // Get Data in Radio Form Html----------------- $id_tags = $this->params()->fromRoute('id'); $get_tags = $this->getSliderTable()->getSlider($id_tags); $view->setVariable('get_tags', $get_tags); /// End Get Data in Radio Form Html $view->setVariable('catalogform', $form); return $view; } else { $view->check = 2; $this->layout('error/admin'); } }