Passing Variable To Buttonurl Outside Of Data In Cgridview

i my cgrid view, i need to pass three variable to the viewbuttonurl but these variables are outside of the model.

this is my code

$outvar = NULL;

$lettervar = NULL;

$certvar = NULL;


$this->widget('zii.widgets.grid.CGridView', array(






                'class' => 'CButtonColumn',

                'template' => '{view}',



				'viewButtonUrl'=>'Yii::app()->controller->createUrl("view",array("id"=>$data->id,"outvar"=>$outvar, \'lettervar\'=>$lettervar, \'certvar\'=>$certvar))',




i got this error:

Undefined variable: outvar

C:\xampp\htdocs\yii\framework\base\CComponent.php(606) : eval()'d code(1)

what is the problem?

The problem is that string expression evaluates in different context.

You can do this for example:

'viewButtonUrl'=>'Yii::app()->controller->createUrl("view",array("id"=>$data->id,"outvar"=>' . $outvar . ', \'lettervar\'=>' . $lettervar . ', \'certvar\'=>$certvar))'

i write this:

				'viewButtonUrl'=>'Yii::app()->controller->createUrl("view",array("id"=>$data->id,"outvar"=>' . $outvar . ', "lettervar"=>' . $lettervar . ', "certvar"=>'. $certvar . '))',

the admin page now appears, but in the button place i got this error:

Parse error: syntax error, unexpected ‘,’ in C:\xampp\htdocs\yii\framework\base\CComponent.php(606) : eval()'d code on line 1

where is the problem?

You should probably wrap vars in quotes

“outvar”=>"’ . $outvar . '",

because they can be empty.

And remember, btw, that this is not a good solution because of possible code injection.

I’d rather go with something like

$outvar =...;

$lettervar = ...;

$certvar = ...;

$url = Yii::app()->controller->createUrl("view", array(

    "id" => '_ID_',

    "outvar" => $outvar, 

    "lettervar" => $lettervar, 

    "certvar" => $certvar


'viewButtonUrl'=>'str_replace("_ID_", $data->id, "' . $url . '")'

But maybe you should look at the widget’s source code (or docs if any), I suppose there’s much better solution


thank you very much for your help