/** * Creates a new MstAccount model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreateUser() { $model = new MstAccount(); $date = date('Y-m-d H:i:s'); // @TODO Use Yii dateformatter // set defaults // @TODO: transfer updating of status/created/updated details to model // set status, created and updated details $model->status = Yii::$app->params['STATUS_ACTIVE']; $model->creator_id = Yii::$app->user->id; $model->created_date = $date; $model->updater_id = Yii::$app->user->id; $model->updated_date = $date; // get plant list $plant_location_list = Yii::$app->modelFinder->getPlantList(null, ['status' => Yii::$app->params['STATUS_ACTIVE']], 'plant_location'); $assignment_list = ArrayHelper::map($plant_location_list, 'plant_location', 'plant_location'); if ($model->load(Yii::$app->request->post())) { $model->password = md5($model->password); // convert to correct date format $model->start_date = Yii::$app->dateFormatter->convert($model->start_date); $model->end_date = Yii::$app->dateFormatter->convert($model->end_date); if ($model->save()) { return $this->redirect(['view-user', 'id' => $model->id]); } else { return $this->render('create-user', ['model' => $model, 'assignment_list' => $assignment_list]); } } else { return $this->render('create-user', ['model' => $model, 'assignment_list' => $assignment_list]); } }