如何使用数据从一个视图重定向到另一个视图 - Yii2

How to Redirect from one view to another view with data - Yii2

我想使用 post 方法将 1 个变量从一个视图传递到另一个视图。使用此重定向代码但它不起作用

 Yii::$app->getResponse()->redirect('home','id'=>$id)->send();

试试这个

Yii::$app->getResponse()->redirect(['home','id' => $id])->send();

为了控制器上下文的完整性,您可以使用:

class MyController extends \yii\web\Controller
{
    public function actionIndex()
    {
        return $this->redirect(['home', 'id' => 123]);
    }
}

其中redirect()的数组参数等于yii\helpers\Url::to()