Пример #1
0
 public function editAction()
 {
     $form = new Admin_Form_GalleryForm();
     $form->submit->setLabel("Save");
     $galleryModel = new Admin_Model_Gallery();
     $id = $this->_getParam('id', 0);
     $data = $galleryModel->getDetailById($id);
     $form->populate($data);
     $this->view->form = $form;
     try {
         if ($this->getRequest()->isPost()) {
             if ($form->Valid($this->getRequest()->getPost())) {
                 $formData = $this->getRequest()->getPost();
                 $id = $formData['gallery_id'];
                 unset($formData['gallery_id']);
                 unset($formData['submit']);
                 $galleryModel->update($formData, $id);
                 $this->_helper->FlashMessenger->addMessage(array("success" => "Successfully Gallery edited"));
                 $this->_helper->redirector('index');
             }
         }
     } catch (Exception $e) {
         $this->_helper->FlashMessenger->addMessage(array("error" => $e->getMessage()));
     }
 }
 public function editAction()
 {
     $form = new Admin_Form_GalleryForm();
     $id = $this->_getParam('id');
     if ($id == null) {
         $this->_helper->redirector('index');
     } else {
         $image = $this->_db->find($id)->current();
         if (null == $image) {
             $this->_helper->redirector('index');
         }
     }
     $form->populate($image->toArray());
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost('gallery');
         if ($form->isValid($post)) {
             $data = array('source' => $form->getValue('source'), 'caption' => $form->getValue('caption'), 'caption_en' => $form->getValue('caption_en'), 'updated_at' => date('Y-m-d H:i:s'), 'updated_by' => $this->_userInfo->id);
             if ($form->image->isUploaded()) {
                 if ($form->image->receive()) {
                     $data['image'] = $form->getValue("image");
                 }
             }
             $this->_db->update($data, array("id = ?" => $id));
             $this->_helper->redirector('index');
         }
     }
     $this->view->form = $form;
     $this->view->image = $image->image;
 }