Beispiel #1
0
 /**
  * Creates a new Address model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Address();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionCreate()
 {
     $model = new Address();
     $model->user_id = Yii::$app->user->id;
     if ($model->load(Yii::$app->request->post(), '') && $model->save()) {
         return ['status' => 'success', 'data' => []];
     } else {
         return ['status' => 'fail', 'data' => ['errors' => $model->getFirstErrors()]];
     }
 }
 /**
  * Creates a new Address model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new Address();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionAdd()
 {
     $model = new Address();
     $model->load(Yii::$app->request->post());
     $model->user_id = Yii::$app->user->id;
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if (Yii::$app->request->isPost && $model->save()) {
         Yii::$app->session->setFlash('success', '您已成功添加收货人是 ' . $model->consignee . ' 的收货地址。');
         return $this->redirect(['index']);
     }
     return $this->render('form', ['model' => $model]);
 }
 public function actionAddressAdd()
 {
     $model = new Address();
     $model->load(Yii::$app->request->post());
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if (Yii::$app->request->isPost) {
         $model->user_id = Yii::$app->user->id;
         $model->save();
     }
     if (Yii::$app->request->referrer) {
         return $this->redirect(Yii::$app->request->referrer);
     } else {
         return $this->redirect(['index']);
     }
 }
Beispiel #6
0
 public function actionAddress($id = null)
 {
     if ($id) {
         $model = Address::findOne($id);
         if ($model === null) {
             throw new NotFoundHttpException('model does not exist.');
         }
     } else {
         $model = new Address();
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->user_id = Yii::$app->user->id;
         if ($model->save()) {
             return $this->redirect(['cart/checkout']);
         }
     }
     return $this->render('address', ['model' => $model]);
 }