YII CGridView错误(YII CGridView error)

2019-10-21 03:43发布

控制器:

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;

                    },
            ),

NEED! :

$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

需要下载这就是我控制器链接的文本($文本)$文本是一个我写出来的表,但是当它是一个变量不能正常工作,正常的文字作品,例如回声“文本”。$ DATA-> ID;

Answer 1:

你可以像下面这样做:

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

希望这对你的作品



文章来源: YII CGridView error
标签: php yii