Fedor Filippov
Fedor Filippov

Reputation: 71

GET-parameter into controller Yii 2

Can I pass GET-parameter into controller action when I click on a link?

Controller action:

public function actionFilter() {
    $categoryId = Yii::$app->request->get('id');

    return $this->render('index', compact('categoryId'));
}

Link:

<?= Html::a('Horror', ['site/filter'], [
        'data' => [
          'method' => 'get',
          'params' => [
            'id' => 'horror',
          ],
        ]
]); ?>

In HTML link seems like:

<a href="/bs/web/index.php?r=site%2Ffilter" data-method="get" data-params="{"id":"horror"}">Horror</a>

Action controller don`t calling. With POST-request it works correct.

Upvotes: 1

Views: 1760

Answers (2)

Fedor Filippov
Fedor Filippov

Reputation: 71

Answer:

<?= Html::a('Horror', ['site/filter', 'id' => 'horror']); ?>

Upvotes: 1

ScaisEdge
ScaisEdge

Reputation: 133400

You can use the simple call for both

<?= Html::a('Horror', ['site/filter', 'id' => 'horror']); ?>

Upvotes: 2

Related Questions