在GridView中的Yii Custom列,具有Font Awesome图标的条件

时间:2013-11-20 21:45:05

标签: php twitter-bootstrap yii font-awesome

我一直在尝试使用fontAwesome在列中渲染图标。我可以用图像完成它,但我无法根据真/假条件显示fontAwesome图标。任何帮助将不胜感激。

这是代码,第1列是我试图用Fontawesome显示的列并且不起作用,第2列使用的是图像并且工作正常。

<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'           => 'vpolicy-grid',
'dataProvider' => $model->searchForPolicyIndex(),
'filter'       => $model,
'type'         => 'striped condensed',
'selectableRows'   => 1, // you can select only 1 row!!
'selectionChanged' => 'function(id){ var objectId = $.fn.yiiGridView.getSelection(id);
if (isNaN(objectId) || objectId == ""){return;} location.href = "'.$this->createUrl('policy/view').
'&id="+$.fn.yiiGridView.getSelection(id);}',

'columns'=>array(
  array('name'              => 'has_open_issue',
        'header'            => 'Issues',
        'type'              => 'raw',
        'value'             => '($data->has_open_issue == "N") ? "<i class="icon- fa-check icon-2x"></i>" : "<i class="icon-fa-warning-sign icon-2x"></i>"',
        'filter'            => VFFormUtil::getFilter_YesNo(),
        'headerHtmlOptions' => array('style' => 'text-align: center; width: 80px'),
        'htmlOptions'       => array('style'=>'text-align: center; width: 80px'),),
  array('name'              => 'compliance',
        'type'              => 'raw',
        'value'             => 'CHtml::image($data->compliance == "INSUFFICIENT" ? "images/policy_insufficient.png" : "images/policy_sufficient.png", "", array("width"=>25, "height"=>25))',
        'filter'            => VFFormUtil::getFilter_Compliance(),
        'headerHtmlOptions' => array('style' => 'text-align: center; width: 80px'),
        'htmlOptions'       => array('style'=>'text-align: center; width: 80px'),),

我也尝试过:

'value'=> 'CHtml::tag($data->has_open_issue == "N" ? "<i class="icon-fa-check icon-2x" style="color:green"></i>" : "<i class="icon-fa-warning-sign icon-2x" style="color:red"></i>", "", array("width"=>25, "height"=>25))',

它也没用。我做错了什么?

1 个答案:

答案 0 :(得分:1)

您需要转义标记属性的引号,即

'value'=> '($data->has_open_issue == "N") ? "<i class=\"icon- fa-check icon-2x\"></i>" : "<i class=\"icon-fa-warning-sign icon-2x\"></i>"',

而不是

'value'=> '($data->has_open_issue == "N") ? "<i class="icon- fa-check icon-2x"></i>" : "<i class="icon-fa-warning-sign icon-2x"></i>"',