How can I insert a selected CGridView value in the databse?

Good morning, I’m a bit confused on how can I get a value selected from a CGridView. I have the following scenario:

-The user has a friend list, he gets a CGridView with the possible people he may add as friends.

-Then picks one and clicks a button to send a request

My main issue is I don’t know how to get this value in php side to add it in the Active Record to save it in database, since the selectionChanged property is a javascript method and I don’t know how to parse this value in a php variable.

Thank you in advance for your kind help :) if you need more input about anything let me know

i did an small extension xbuttoncolumn while ago , what it does is adding an button column in addition to yii built-in buttons (view, edit, delete) which flips status flag yes/no, true/false, and it does update active record.

if you find it fit your scenario, you can modify the controller action to add/remove the friend relation.

it’s just an idea, not so hard to figure it out, also customized button-column would also work with messy ajax tricks.

Thank you for your repply rootbear, I’ll go check it out now :) I was trying to avoid the button column but if this works I could apply it, is there a way to make something similar with some button component?

Thank you very much for your answer


This wiki uses ajax that determines which row and COLUMN in the CgridView was clicked. It extracts the column’s data and send it to the controller - where you can save it to database.