Пример #1
0
 public function addAction()
 {
     $form = new Admin_Form_GalleryForm();
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             unset($formData['submit']);
             unset($formData["gallery_id"]);
             try {
                 $galleryModel = new Admin_Model_Gallery();
                 $galleryModel->add($formData);
                 $this->_helper->FlashMessenger->addMessage(array("success" => "Successfully Gallery added"));
                 $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;
 }