Yii2 Button with Parameter

我是研究僧i 提交于 2019-12-11 10:19:45

问题


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



来源:https://stackoverflow.com/questions/29227225/yii2-button-with-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!