예제 #1
0
 public function create()
 {
     if (!$this->has_post()) {
         return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。'));
     }
     $posts = OAInput::post();
     $cover = OAInput::file('cover');
     if (!$cover) {
         return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => '請選擇照片(gif、jpg、png)檔案,或提供照片網址!', 'posts' => $posts));
     }
     if ($msg = $this->_validation_posts($posts)) {
         return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => $msg, 'posts' => $posts));
     }
     $posts['sort'] = Promo::count();
     $create = Promo::transaction(function () use($posts, $cover) {
         return verifyCreateOrm($promo = Promo::create(array_intersect_key($posts, Promo::table()->columns))) && $promo->cover->put($cover);
     });
     if (!$create) {
         return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => '新增失敗!', 'posts' => $posts));
     }
     return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '新增成功!'));
 }