예제 #1
0
 public function createEvent()
 {
     $event = new Event();
     $event->attributes = ['user_id' => Yii::$app->user->id, 'city' => $this->city, 'theme' => $this->theme, 'description' => $this->description, 'urgent' => $this->urgent, 'occur_at' => $this->occur_at];
     $event->save();
     $this->_event = $event;
 }
예제 #2
0
 /**
  **创建一个新的事件.如果创建成功,浏览器会跳转到该事件的详情页面.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Event();
     try {
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(Url::previous());
         } elseif (!\Yii::$app->request->isPost) {
             $model->load($_GET);
         }
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         $model->addError('_exception', $msg);
     }
     return $this->render('create', ['model' => $model]);
 }