【问题标题】:renderPartial in CGridView cell在 CGridView 单元格中呈现部分
【发布时间】:2012-09-05 11:10:54
【问题描述】:

我想在 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))

我不明白这个错误。 $this 是 BookController 的实例,而 BookController 是 CController 的子节点。

【问题讨论】:

    标签: php gridview yii


    【解决方案1】:

    在另一个Yii programmer的帮助下找到了解决方案

    $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);
              }
          )
      ),
    ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 2013-11-07
      • 1970-01-01
      相关资源
      最近更新 更多