user2172603
user2172603

Reputation: 31

Yii, set radio button value fetch from database

In Yii, I listed my table which is fetch from database in grid view.

'value'=> 'CHtml::radioButton("set_default",false,array(
             "value"=>"$data->id",
             "set"=>"1",
             "disable"=>"disable",
              "uncheckValue"=>null  
            ))',

the above code I entered in normal radio button view, how do I fetch from database? Anybody help me?

Upvotes: 1

Views: 565

Answers (1)

hamed
hamed

Reputation: 8033

CGridView lets you write any value inside row's column instead of normal database values. For modify column values, you need to add a function for value attribute. Inside of this function, you can access each data's attributes. In your case, You need to echo a radio button like this:

 //$data refres to each data row in the CGridView
'value' => function ($data, $row) {
        echo  
        CHtml::radioButton("set_default",false,array(
            "value"=>$data->id,
            "set"=>"1",
            "disable"=>"disable",
            "uncheckValue"=>null  
        )),                      
 },

Upvotes: 0

Related Questions