YII CGridView错误

时间:2014-10-20 13:18:53

标签: php yii

控制器:

public function actionItem($textdata){
        $dataProvider = new CActiveDataProvider('Mytest', array(
            'criteria' => array(
                'condition' => 'type="'.$textdata.'"',
            ),
        ));
$bleble = $textdata;
        $this->render('Item', array(
            'dataProvider' => $dataProvider,
            'bleble' => $bleble,
        ));
    }

视图:

$bleble = $bleble;

$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'sample_id',
    'dataProvider' => $dataProvider,
    'columns' => array(
        array(
                'header' => 'id',
                    'name'   => 'id',
                    'value'  =>'$data->id',
                    'type'   =>'raw',
                    "value"  => function($data){
                        echo "text".$data->id;

                    },
            ),

需要!! :

$bleble = $bleble;

    $this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'sample_id',
        'dataProvider' => $dataProvider,
        'columns' => array(
            array(
                    'header' => 'id',
                        'name'   => 'id',
                        'value'  =>'$data->id',
                        'type'   =>'raw',
                        "value"  => function($data){
                            echo $bleble.$data->id;

                        },
                ),

错误:

PHP通知 未定义的变量:bleble

需要下载链接的文本,这是我的控制器($ text)$ text是我必须写出来的那个,但是当它是变量时不起作用,普通文本适用于例如echo“text ” $ DATA-> ID;

1 个答案:

答案 0 :(得分:2)

你可以这样做:

"value" => function($data) use ($bleble){
    return $bleble.$data->id;
}

希望这适合你