rasha1489
(Rasha1489)
1
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(
'id'=>'assignment-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'class' => 'CButtonColumn',
'template' => '{view}',
'viewButtonUrl'=>'Yii::app()->controller->createUrl("view",array("id"=>$data->id,"outvar"=>$outvar, \'lettervar\'=>$lettervar, \'certvar\'=>$certvar))',
//'updateButtonUrl'=>'Yii::app()->controller->createUrl("update",$data->primaryKey)',
//'deleteButtonUrl'=>'Yii::app()->controller->createUrl("delete",$data->primaryKey)',
),
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))'
rasha1489
(Rasha1489)
3
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
rasha1489
(Rasha1489)
6
Solved
thank you very much for your help