![](/img/trans.png)
[英]Redirecting WordPress page without changing the URL or doing a 301
[英]Changing the model without redirecting to the update page
在我的控制器中有一个update方法,我想要这样,如果我单击update按钮,则$ model-> status =('Done'); 而不将其重定向到更新页面。
到目前为止我尝试过的内容会刷新页面,但是$ model-> status不会更改为“ Done”
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
$model->status = ('Done');
$model->time_end = date('y-m-d h-i-s');
return $this->redirect(['view', 'id' => $model->id]);
}
}
没关系,我已经找到了解决方案:
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->status = ('Done');
$model->time_end = date('y-m-d h-i-s');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('view', [
'model' => $model,
]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.