Beispiel #1
0
 /**
  * Creates a new Essay model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Essay();
     if ($model->load(Yii::$app->request->post())) {
         $model->title = Yii::$app->request->post()['Essay']['title'];
         $model->date = date("Y-m-d");
         $model->author = "wd1900";
         $model->body = Yii::$app->request->post()['Essay']['body'];
         $model->insert();
         return $this->redirect(['view', 'id' => (string) $model->_id]);
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // return print_r(Yii::$app->request->post());
         // $model->id = Yii::$app->request->post()['Essay']['id'];
         $model->title = Yii::$app->request->post()['Essay']['title'];
         $model->date = date("Y-m-d");
         $model->author = "wd1900";
         $model->body = Yii::$app->request->post()['Essay']['body'];
         // return Yii::$app->request->post();
         return $this->redirect(['view', 'id' => (string) $model->_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }