Yii Booster TbTotalSumColumn格式化为货币

时间:2013-05-21 15:25:53

标签: php yii

我正在使用Yii Booster,其中一个小部件是TbTotalSumColumn。

当它在页脚中呈现总数时,它使用以下代码:

echo $this->totalValue? $this->evaluateExpression($this->totalValue, array('total'=>$this->total)) : $this->grid->getFormatter()->format($this->total, $this->type);

我使用了CFormatter并创建了一种'货币'类型,我已经将格式直接应用于'value'属性,我已进入小部件并在那里应用了货币格式化程序。似乎无论我做什么,我只能将列中的值格式化为货币或页脚,而不是两者。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

我在components文件夹中创建了一个名为TbTotalColumnCurrency.php的新类文件。然后我在TbExtendedGridView代码中调用TbTotalSumColumnCurrency。

Yii::import('bootstrap.widgets.TbTotalSumColumn');

class TbTotalSumColumnCurrency extends TbTotalSumColumn
{
    protected function renderFooterCellContent()
    {
        if(is_null($this->total))
            return parent::renderFooterCellContent();

        echo $this->totalValue? $this->evaluateExpression($this->totalValue, array('total'=>number_format($this->total), 2, '.', '')) : $this->grid->getFormatter()->format(number_format($this->total, 2, '.', ''), $this->type);
    }
}

希望这有帮助

array(
    'name'=>'Total',
    'type'=>'text',
    'value'=>'number_format($data->price*$data->quantity, 2, \'.\', \'\')',
    'class'=>'TbTotalSumColumnCurrency'
),
相关问题