Skip to content

mdmsoft/yii-auto-date-format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

yii-auto-date-format

Yii1 behavior to automatic convert date format

Instalation

Download and extract to your extension directory.

Usage

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',
	),
));

About

Yii1 behavior to automatic convert date format

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published