Yii2-如何通过重定向传递模型ID

Yii2- How to pass model id via redirect

您好,我想使用 url 在重定向中传递模型 ID。但是当我尝试通过它时,出现错误

错误

Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

当我尝试这样做时出现此错误

$this->redirect(Url::to('/process?file_name=' . $file_name . "&header_no=" . $_POST['header_no'],['id'=>$model->id]));

URL : http://localhost:225/process?file_name=excel_12.xlsx&header_no=1 Url 错了 正确的应该是这样 http://localhost:225/inventory-web/backend/web/....../...

错误2:

Not Found (#404) Page not found. The above error occurred while the Web server was processing your request.

Please contact us if you think this is a server error. Thank you.

URL:http://localhost:225/inventory-web/backend/web/process?file_name=excel_12.xlsx&header_no=1?id=1

如何传递模型 ID?

任何帮助将不胜感激

我已经试过了,对我来说效果很好。

$this->redirect('/didmaster/didtenant?id=' . $model['em_id']);

试试这个,

 $this->redirect('/process?file_name=' . $file_name . "&header_no=" . $_POST['header_no'] . "&id=" . $model->id);

 $this->redirect(array(
        'process',
        'file_name' => $file_name,
        'header_no' => $_POST['header_no'],
        'id' => $model->id
    ));

如 yii2 参考 https://www.yiiframework.com/doc/api/2.0/yii-web-controller#redirect()-detail

你可以使用

an array in the format of [$route, ...name-value pairs...] (e.g. ['site/index', 'ref' => 1]) yii\helpers\Url::to() will be used to convert the array into a URL

$this->redirect(['/process', 'file_name'=> $file_name, 
                             'header_no'=> $_POST['header_no'] ,
                             'id'=>$model->id]);

您也可以使用来自响应的重定向:

 Yii::$app->response->redirect(['/process', 'file_name'=> $file_name,
            'header_no'=> $_POST['header_no'] ,
            'id'=>$model->id]);