renderPartial在CGridView单元中


renderPartial in CGridView cell

我想在CGridView的单元格中呈现一个php视图文件。

因此我写了这个代码:

$this->widget('zii.widgets.grid.CGridView', array(
  'dataProvider'=>$dataProvider,
  'columns'=>array(
      array(
          'value'=>array($this, 'renderPartial("_lineProblems")')
      ))));

但我得到了这个错误:

BookController and its behaviors do not have a method or closure named "renderPartial('_lineProblems' )".

堆栈跟踪显示这是问题所在:

call_user_func_array(array(BookController, "renderPartial('_lineProblems' )"), array("data" => line, "row" => 0, 0 => CDataColumn))

我不明白这个错误$这是BookController的一个实例,BookController是CController的子级。

在另一位Yii程序员的帮助下找到了一个解决方案

$controller = $this;
$this->widget('zii.widgets.grid.CGridView', array(
  'dataProvider'=>$dataProvider,
  'columns'=>array(
      array(
          'name'=>'errors',
          'value'=>function($data, $row) use ($controller){
                return $controller->renderPartial('_lineProblems', array('errors'=>$data->errors), true);
          }
      )
  ),
));