Hi, I have a custom checkbox in a CGridView column in one of my views. Without going into too much detail I can’t use relations to solve the problem.
I have two tables, X which has a model and is used to render the CGridView, and Y which doesn’t have a model or controller. There is a foreign key in table Y that ties to X.id. The custom checkbox is used to “copy” that row into table Y (with code in X.controller) and if it is already checked then it indicates that that row already exists in table Y.
Before the grid is created I have code that populates an array with the array keys created with the foreign key and some text strings to create a unique id for the checkbox.
The following code currently generates this error:
you cant do this because CHtml::checkBox() i defined method, any you cant call function array_key_exists
in method function parameters
CHtml::checkBox() is defined
public static function checkBox($name,$checked=false,$htmlOptions=array())
$value=isset($htmlOptions['value']) ? $htmlOptions['value'] : 1;
// add a hidden field so that if the radio button is not selected, it still submits a value
if(isset($htmlOptions['id']) && $htmlOptions['id']!==false)
// add a hidden field so that if the checkbox is not selected, it still submits a value
return $hidden . self::inputField('checkbox',$name,$value,$htmlOptions);
My solution was to loop through the array and create a string that represented the array (ie: array("cid_testRow_1"=>1)). Then I overrode CHtml::checkBox converting the "checked" value to an array. Then because the id and name parameters of the checkbox are the same, I could use array_key_exists to compare the already passed in $name value against the array.