Yii1 behavior to automatic convert date format
Download and extract to your extension directory.
On your ActiveRecord class, add to method behaviors()
:
function behaviors()
{
return array(
'AutoDateFormat' => array(
'class' => 'ext.MdmAutoDateBehavior',
'logicalFormat' => 'd-m-Y',
'physicalFormat' => 'Y-m-d',
'attributes' => array(
'orderDate' => 'order_date', // mapping attribute from logical to physical filed.
),
),
...
);
}
Then, for this AR, use attribute orderDate
instead of order_date
.
$model->orderDate = '27-05-2014';
equivalent with
$model->order_date = '2014-05-27';
on your form
$form->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'orderDate',
'options' => array(
'showAnim' => 'fold',
'dateFormat' => 'dd-mm-yy',
),
'htmlOptions' => array(
'style' => 'height:20px;',
'size' => '12',
),
));