Hi,
I have developed the application with en_US source language (Yii 1.1.4).
My language target is es_es (date format: aa-mm-YYYY instead of YYYY-mm-aa; number format: ‘,’ is the decimal separator and ‘.’ is the thousand separator).
I have setup the main.php putting:
'language'=>'es_es',
I use the CDateFormatter and CNumberFormatter to change the format of the variables and works fine. For example:
Yii::app()->locale->dateFormatter->formatDateTime($historial_estados->fecha,'long',null))
Well, my problem is when I try to change the format of the values if they are attributes of a model. I don’t know how to use the locate in this situation. For example to a date variable call “fecha”:
Model:
======
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id_asociado, id_estado, fecha', 'required'),
array('id_asociado, id_estado', 'length', 'max'=>10),
array('fecha', 'type', 'type'=>'date' ,'dateFormat'=>Yii::app()->locale->dateFormat),
array('notas', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id_historial, id_asociado, id_estado, fecha, notas, timestamp', 'safe', 'on'=>'search'),
);
}
View/Form:
==========
<div class="row">
<div style="min-width: 150px; float: left">
<?php echo $form->labelEx($model,'fecha'); ?> (DD/MM/AAAA)
</div>
<?php
echo $form->textField($model,'fecha');
?>
<?php echo $form->error($model,'fecha'); ?>
</div>
Could I use anything to show "fecha" in the correct format depends of the locale used?
And, then automatic format conversion to save (from the form to database) to a model without use beforeSave function too? (Actually I’m using a beforeSave to change the format but this way doesn’t depend of the locale value).
I’m searching how to configure numeric and datetime model attributes that they have a automatic correct format depends of the locale value in main.php.
Is possible?
Thanks in advanced.
PD: Sorry for my english.