yii CGridView:将字符串与 link 中的变量连接起来

yii CGridView: concatenate string with variable in link

无法将字符串与变量连接起来。

等待您的建议,伙计们。

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $model->search(),
    'columns'=>array(
        array (
            //'value'=>'CHtml::link("Some text", Yii::app()->createUrl("/example/registration&exampleID=".$data->exampleID))',  // DONT work
            'value'=>'CHtml::link("Some text", Yii::app()->createUrl("/example/registration&exampleID=112"))',
            //'value'=>'CHtml::link("Some text", "/index.php?r=/example/registration&exampleID=".$data->exampleID)',            // DONT work
        ),
    ),
));

您需要为 value 使用 function:

$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'columns'=>array(
    array (
     'value' => function ($data, $row) {
         echo CHtml::link("Some text", Yii::app()->createUrl("/example/registration&exampleID=".$data->exampleID));
       },
      )  
   ),
));

这会很有帮助。