Ejemplo n.º 1
0
 public function themAction()
 {
     // TODO Auto-generated {0}::indexAction() default action
     $this->view->form = $form = new Admin_Form_TaiLieu_Create();
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $table = Khcn_Api::_()->getDbTable('tai_lieu', 'default');
     $db = $table->getAdapter();
     $db->beginTransaction();
     try {
         $tai_lieu = $table->createRow();
         if ($form->file->getFileName(null, false) != null) {
             //determine filename and extension
             $info = pathinfo($form->file->getFileName(null, false));
             $filename = $info['filename'];
             $ext = $info['extension'] ? "." . $info['extension'] : "";
             //filter for renaming.. prepend with current time
             $file = time() . '_' . Default_Model_Functions::convert_vi_to_en($filename) . $ext;
             $form->file->addFilter(new Zend_Filter_File_Rename(array("target" => $file, "overwrite" => true)))->addFilter(new Khcn_Filter_File_Resize(array('width' => 720, 'height' => 720, 'keepRatio' => true)));
             $form->getValue('file');
             $tai_lieu->ten_file = $file;
         }
         $values = $form->getValues();
         $values['ngay_tao'] = date('Y-m-d H:i:s');
         $tai_lieu->setFromArray($values);
         $tai_lieu->save();
         $db->commit();
         $_SESSION['msg'] = 'Thành công !. Dữ liệu đã được lưu trữ .';
         $_SESSION['type_msg'] = 'success';
         if ($form->submitCon->isChecked()) {
             $this->_redirect('/admin/tai-lieu/them');
         } else {
             $this->_redirect('/admin/tai-lieu/index');
         }
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
 }
Ejemplo n.º 2
0
 public function init()
 {
     parent::init();
 }