我的模型中有一个 afterSave 函数,它根据用户给出的开始时间和持续时间保存某些服务的到期日期。我的 afterSave
工作正常,但在保存模型后它没有被重定向而是显示空白页。
型号:
public function afterSave($insert)
{
$month= "+".$this->duration_in_months." month";
$this->exp_date=date("Y-m-d H:i:s",strtotime($month));
$this->save(['exp_date']);
return parent::afterSave($insert);
}
Controller :
if($model->save())
return $this->redirect(['view', 'id' => $model->sub_id]);
}
我如何重定向 afterSave?提前致谢!
最佳答案
正确的方法是从 Controller 调用save()
,它会隐式调用afterSave()
。
您只需在 Controller-Action 中执行此操作 -
if($model->save()) {
$this->redirect(……);
}
关于php - yii2 中的 afterSave 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23424827/