/** * Creates a new MsgOfDay model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new MsgOfDay(); if ($model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } $model->attributes = $_POST['MsgOfDay']; $model->created_by = Yii::$app->getid->getId(); $model->created_at = new \yii\db\Expression('NOW()'); if ($model->is_status == 0) { $model->updateAll(['is_status' => 1], 'is_status <> 2'); $model->is_status = 0; } if ($model->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }