Hi cheeserolls,
I found your post really useful for mapping database values which are abbreviations to meaningful names. Here is an example:
protected/config/main.php:
[code]
return array(
[...]
'components'=>array(
'format'=>array(
'class'=>'MyFormatter',
),
[...]
The custom component looks like this:
protected/components/MyFormatter.php:
<?php
/**
* MyFormatter is the customised formatter class.
*/
class MyFormatter extends CFormatter
{
/**
* @var array the text to be displayed when formatting a frequency value.
* Each key corresponds to the value that will be displayed.
*/
public $frequencyFormat=array(
'D'=>'Daily',
'W'=>'Weekly',
'M'=>'Monthly',
'Y'=>'Yearly',
);
/**
* Formats the value as a HTML-encoded frequency.
* @param mixed the value to be formatted
* @return string the formatted result
*/
public function formatFrequency($value)
{
if(!empty($this->frequencyFormat[$value]))
return CHtml::encode($this->frequencyFormat[$value]);
else
throw new CException(Yii::t('yii','Unknown frequency "{frequency}".',array('{frequency}'=>$value)));
}
}
Finally, this is used in a widget as follows:
protected/views/myview/_something.php:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model,
'columns'=>array(
'charge_name'
'charge_amount',
array(
'name'=>'charge_frequency',
'type'=>'frequency',
'value'=>'CHtml::encode($data->charge_frequency)',
),
),
));
?>
More to the point of your message though, I tackled the currency symbol issue as follows:
protected/config/main.php:
<?php
return array(
[...]
'params'=>array(
[...]
'currency'=>'GBP',
),
[...]
protected/views/myview/_detail.php:
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'address.address_line_1',
'address.address_line_2',
'address.city',
'address.postcode',
'property_type',
'property_value',
array(
'name'=>'valuation_date',
'type'=>'raw',
),
array(
'name'=>'rental_value',
'type'=>'raw',
'value'=>Yii::app()->numberFormatter->formatCurrency($model->rental_value,
Yii::app()->params->currency),
),
),
)); ?>
Just thought I would share these alternatives with the community…