コード例 #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()) {
         Yii::$app->getSession()->addFlash('success', "Запись \"{$model->fullName}\" успешно добавлена.");
         return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]);
     } else {
         if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) {
             Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null);
         }
         if (!Yii::$app->request->isPost) {
             $model->load(Yii::$app->request->get());
         }
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
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(['view', 'address_id' => $model->address_id, 'province_id' => $model->province_id, 'country_id' => $model->country_id, 'customer_id' => $model->customer_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #3
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();
     $model->user_fk = Yii::$app->user->identity->user_id;
     $countries = ArrayHelper::map(Country::find()->all(), 'country_id', 'country');
     $cities = ArrayHelper::map(City::find()->all(), 'city_id', 'city');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->address_id]);
     } else {
         return $this->render('create', ['model' => $model, 'countries' => $countries, 'cities' => $cities]);
     }
 }
コード例 #4
0
ファイル: CartController.php プロジェクト: irying/artist
 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]);
 }