kushal33

yii2 create user code

Jan 10th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1.     public function actionCreate()
  2.     {
  3.         if(Yii::$app->user->identity->status==User::USER)
  4.         {
  5.             throw new HttpException(403, "Access Denied");
  6.         }
  7.         $model = new User();
  8.         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
  9.             $model->password = md5($model->password);
  10.             $location = Locations::find()->andFilterWhere(['and',
  11.             ['=', 'zip_code', $model->zip],
  12.             ['like', 'street_name', $model->street],
  13.             ['like', 'district', $model->district],
  14.             ])->all();
  15.             $model->location_id=$location[0]->id;
  16.             if($model->save())
  17.             {
  18.                 Yii::$app->session->setFlash('success', common::translateText("ADD_SUCCESS"));
  19.             }
  20.             else{
  21.             Yii::$app->session->setFlash('error', common::translateText("ADD_FAIL"));
  22.             }
  23.             return $this->redirect(['index']);
  24.         } else {
  25.             return $this->render('_form', [
  26.                 'model' => $model,
  27.             ]);
  28.         }
  29.     }
Add Comment
Please, Sign In to add comment