This extension is a behavior that can be used in models to allow them to automatically parse and format i18N date formats.
The behavior scans for date and datetime fields in the model attributes, and do the conversions needed.
September 30, 2009
Fixed issue with optional date/datetime fields and incorrect convertion on datetime fields (works only with Yii 1.0.9. If you use this version, download I18N-datetime-behavior 1.1. If not, use the original version)
August 17, 2009
Requirements
- Yii 1.0.9 or above
- You need to have defined your desired language at the entry script.
Installation
- Extract the release file and put it under
protected/extensions
Usage
In you model, add the following code:
public function behaviors()
{
return array('datetimeI18NBehavior' => array('class' => 'ext.DateTimeI18NBehavior')); // 'ext' is in Yii 1.0.8 version. For early versions, use 'application.extensions' instead.
}
IMPORTANT!
This behavior changes afterFind and beforeSave events. If your model have to have coding, please, don't forget to add the parent reference:
protected function beforeSave(){
if (!parent::beforeSave()) return false;
....your code
}
The same for afterFind method. Otherwise, this behavior will not make effect.
Note: This extension was made for MySQL. But, it can be easily changed to be useful to other databases.
Note2: Actually, the extension have problems with datetime fields, just working with date fields (FIXED)
Use version 1.1 if you are using Yii 1.0.9. If not, use the original version (with the bug described on note #2)