Passing variables between actions

Here goes my second dumb question of the week…

I am trying to pass variables between actions using redirect:

From:




public function actionCreate()

    {

        $model = new Profile();

        $model->scenario = 'create';

        if ($model->load(Yii::$app->request->post()) && $model->createProfile()) {

            return $this->redirect('form1', ['id' => $model->id,]);

        } else {    

            return $this->render('create', ['model' => $model,]);

        }

    }



To:




public function actionForm1()

    {

        $id = <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />;

        $model = profile::findOne($id);



I have checked every resource I have available and cannot figure how to capture the variable. I know the answer is simple.

Just add argument:


public function actionForm1($id) 

I tried that and it doesn’t work. $id before being passed is “8”, and if I use actionForm1($id), $id then becomes “profile”, the name of the controller class.

Check your code because this




public function actionTest()

{

    return $this->redirect(['test2', 'id' => 4]);

}

    

public function actionTest2($id)

{

    var_dump($id);die;

}



should give you


string '4' (length=1)

I guess you are calling $this->id which if called in controller gives you controller’s id.

Yes, that’s what I was doing. I also see that I have to place both arguments of redirect in the same array. Thanks for your help.