'How to send two parameters to action using button in ActiveColumn Yii2

I am having a little bit of trouble with the ActionColumn in Yii2 basic application.

I want to send two parameters to an action called activate. The action takes one parameter without any issues. However, when I want to send him the second one, it starts to act up.

To get the second parameter I need to loop through an object to get it. However, every time I call the index page I get a Undefined Variable: teamId Error. Not sure what I am missing in the function. Am I doing the loop wrong or anything?

This is what I have in the ActionColumn in the index.php:

[
                'class' => ActionColumn::className(),
                'template' => '{activate}',
                'buttons' => [
                    'activate' => function($url, $model) {
                        $userId = $model->iduser;
                        foreach ($model->teamIdteams as $team) {
                            $teamId = $team->idteam;
                        }
                        // return Html::img($url);
                        return Html::a('Click Me', ['activate', 'id' => $userId, 'team' => $teamId]);
                    }
                ],
            ],

What am I missing here? Any help is much appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source