public function actionUpdate($id)
{
$model = Address::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]);
if (!$model) {
throw new NotFoundHttpException('未找到收货地址!');
}
$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->save()) {
Yii::$app->session->setFlash('success', '您已成功更新收货人是 ' . $model->consignee . ' 的收货地址。');
return $this->redirect(['index']);
}
return $this->render('form', ['model' => $model]);
}