Winkmei5ter
Winkmei5ter

Reputation: 318

Yii2 Button with Parameter

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.

Upvotes: 1

Views: 7336

Answers (1)

vim
vim

Reputation: 1550

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

Upvotes: 4

Related Questions