I'm building a webapp with Yii2 framework that will provide users (logged in) the capability to download pre-uploaded files by administrators.
I've created the action actionDownload
in the specific controller that call the sendFile()
method.
How can I create a button that call the specific action actionDownload
on click in a GridView (the list of documents)?
Extend declaration of template and buttons like this:
The download icon with the url will be added to existing set of icons. You can see for example how default icons are rendered here.
In common case you don't even have to build link manually, it will be constructed based on the button name and model primary key, for example
/download?id=1
.In case you want different url special property exists, it's called $urlCreator, but you can also change it right in the button rendering closure, for example:
How to add another action button in kartik-v yii2 grid action column?
Just see following example.I have added copy button.
template attribute is important