簡體   English   中英

更改模型而不重定向到更新頁面

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM