How to call an action of my controller via Button

Hello everyone

i have a html table which contains data (using for each and CommandQuery)

So i have these 2 buttons which both must do an update query but with different parameters

For Example

I click Not Approved button (it must execute a query which changes the value of 0 to 1; same for approved button and then it redirects me to the view which i was before).

Thanks to any kind of help

If in a GridView check out a ToggleColumn extension.


in your controller, create an actionApprove($id). Send both buttons to this action with a _POST of the value. You could also make two actions and skip the _POST part.

My question would be: If both buttons are visible, How does the user know if this item is approved or not? I would look at the Gii CRUD _form.php for how the button Submit button is done. Instead of the isNewRecord test, use $model->is_approved. One button, one action. Toggle the information in the action. refresh. rinse and repeat :)

Thank you very much

In my controller actually i have this both actions(and with the parameter of $id), the issue is how i can do it or how the url of the button supposed to be

you could use a anchor tag and style with css to make it look like a button, If that does not work you can use javascript to hook an action on click event of the button or alternatively you can create a form with each button group and submit that form when user clicks the button many ways to skin a sheep.

Yeah thank you, but i want to know how can i do it?

So i just use Js, make it redirect to my controller/action?


    Html::a($model->isApproved ? Yii::t('app', 'Disapprove') : Yii::t('app', 'Approved'), 

        ['controller/action', ['id' => $model->record_id]], 

        ['class' => $model->isApproved ? 'btn btn-success' : 'btn btn-primary']);


1 Like