/** * Creates a new Customer model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Customer(); $user = UserAccount::find()->select('id, username')->all(); if ($model->load(Yii::$app->request->post())) { $model->created_at = date("Y-m-d H:i:s"); $model->updated_at = date("Y-m-d H:i:s"); $model->token_expired = date('Y-m-d H:i:s', strtotime($model->token_expired)); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { // print_r($model->errors); return $this->render('create', ['model' => $model, 'user' => $user]); } } else { return $this->render('create', ['model' => $model, 'user' => $user]); } }
/** *Check customer code is unique // use with Active form and field ajax validation */ public function actionCheckcustomeruniquecode() { if (Yii::$app->request->isAjax) { $model = new Customer(); if ($model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } } else { throw new NotFoundHttpException(); } }