1

我有一个像下面这样的网格视图。在这里,我想使用正确答案的值来查找要显示的按钮。

例如,如果正确答案 > 0 则显示刻度按钮,否则显示十字按钮

那么我将如何在网格视图中编写该条件?

$this->widget('zii.widgets.grid.CGridView', array(

    'id'=>'product-table',

    'dataProvider'=>Question::model()->searchCustom(1),

    'columns'=>array(
        array('name'=>'qnid'),
        array('name'=>'question'),
        array('header'=>'Correct Answer','value' =>array($this,'getCorrectAnswer')),
        array(
                'header'=>'Acton',
                'class'=>'CButtonColumn',
                'template'=>'{tick}| {cross}' ,
                'buttons' => array ('tick' => array('imageUrl'=>Yii::app()->request->baseUrl.'/images/correct.png'),
                                    'cross' => array('imageUrl'=>Yii::app()->request->baseUrl.'/images/correct.png'))
            ),

    ),
    'itemsCssClass' => 'table table-striped table-bordered bootstrap-datatable datatable',
    'cssFile'=>false,

));

提前致谢

4

2 回答 2

1

尝试这个

 'buttons' => array ('tick' => 
  array('imageUrl'=>Yii::app()->request->baseUrl.'/images/correct.png',
        'visible'=>'Correct Answer > 0'),
 'cross' => array('imageUrl'=>Yii::app()->request->baseUrl.'/images/correct.png',
                  'visible'=>'Correct Answer <= 0'))
于 2013-10-29T09:59:58.150 回答
-1

尝试这样的事情

array('header'=>'Action','value' =>array($this,'getButton')),

并在控制器中

function getButton($data) {
  $correct_answer = // find it
  if($correct_answer > 0) {
    $button = '<a href="#" class="tick"></a>';
  }
  else {
    $button = '<a href="#" class="cross"></a>';
  }
  return $button;
}
于 2013-10-29T09:59:24.350 回答