how to pass parameter on redirect in yii

前端 未结 4 1991
鱼传尺愫
鱼传尺愫 2021-02-06 23:34

I am using Yii framework for my project;

I am redirecting page after success of insertion in database to another controller using

$this->redir

相关标签:
4条回答
  • 2021-02-06 23:41

    To redirect into same action with the all parameters that already have this works for me.

    $this->redirect($_PHP['SELF']);
    
    0 讨论(0)
  • 2021-02-06 23:52

    You can only pass GET parameters in the Yii 2 redirect(). However, I had a similar situation and I resolved it by using Session storage.

    Naturally, you can access current Session via Yii::$app->session. Here is an example of using it in two separate controller actions:

    public function actionOne() {
        // Check if the Session is Open, and Open it if it isn't Open already
        if (!Yii::$app->session->getIsActive()) {
            Yii::$app->session->open();
        }
        Yii::$app->session['someParameter'] = 'Bool/String/Array...';
        Yii::$app->session->close();
        $this->redirect(['site/two']);
    }
    
    public function actionTwo() {
        if (isset(Yii::$app->session['someParameter']) {
           $param = Yii::$app->session['someParameter'];
        } else {
           $param = null;
        }
        $this->render('two', [
            'param' => $param
        ]);
    }
    

    So now you should be able to access $param inside the two view.

    For more information, please refer to the official class documentation.

    0 讨论(0)
  • 2021-02-06 23:53

    Try:

    $this->redirect(array('controller/action', 'param1'=>'value1', 'param2'=>'value2',...))
    

    api yii 1, api yii 2

    0 讨论(0)
  • 2021-02-07 00:01

    try this:

    Yii::$app->response->redirect(['site/dashboard','id' => 1, 'var1' => 'test']);
    
    0 讨论(0)
提交回复
热议问题