2014-10-20 94 views
1

控制器:YII CGridView错误

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

需要下载这是我怎么控制器($文本)$文本链接的文本的一个我有写出表格,但当它是一个变量时不起作用,普通文本例如echo“text”。$ data-> id;

+0

仍然不能正常工作, “值”=>函数($数据){ 回声$ bleble $ DATA-> ID; }, 我需要以某种方式交换,这是得到的控制器例如文本显示的方式:TEXT_1,TEXT_2,TEXT_3其中数字表示ID – ubgsdnhfj 2014-10-20 14:06:51

回答

2

你能做到这样的:

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

希望这对你的作品

+0

,但正如我有使用? “value”=> function($ data)use $ bleble { return $ bleble。$ data-> id; }, – ubgsdnhfj 2014-10-20 14:08:27

+0

是的,你需要像这样使用它。 – Dinistro 2014-10-20 14:10:02

+0

解析错误:语法错误,意外'$ bleble'(T_VARIABLE),期待'('in' – ubgsdnhfj 2014-10-20 14:10:28