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.
您可以对两者使用简单调用
<?= Html::a('Horror', ['site/filter', 'id' => 'horror']); ?>
回答:
<?= Html::a('Horror', ['site/filter', 'id' => 'horror']); ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.