Yii2 Button with Parameter

2019-08-06 05:48发布

问题:

I have this button in my Yii2 project:

Html::a('label', ['/attributes/index'], ['class'=>'btn btn-primary']) ;

The button is located in the page:

/site/view

Now what I want to do is pass a parameter when this button gets clicked to the attributes/index page from the site/view page.

To be more specific it is the ID that I want to pass of a particular record from a DB I am viewing.

Cheers.

回答1:

You can pass parameters as key => value pairs after the route:

Html::a('label', ['/attributes/index', 'id' => $id], ['class'=>'btn btn-primary']) ;

See the Yii2 docs: http://www.yiiframework.com/doc-2.0/yii-helpers-baseurl.html#toRoute()-detail



标签: php yii2