public function actionAddressEdit($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();
}
if (Yii::$app->request->referrer) {
return $this->redirect(Yii::$app->request->referrer);
} else {
return $this->redirect(['index']);
}
}