YII CGridView error


YII CGridView error

控制器:

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;

你可以这样做:

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

希望这对你有效