Yii 1.1: yii-auto-date-format

Yii1 behavior to automatic convert date format
5 followers

yii-auto-date-format

Yii1 behavior to automatic convert date format

Instalation

Download from this yii-auto-date-format 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', // optional, default d-m-Y
            'physicalFormat' => 'Y-m-d', // optional, default 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',
    ),
));

Total 5 comments

#18371 report it
Misbahul D Munir at 2014/10/22 04:19am
@myrazel

Thanks... if any trouble or something. Fill free to ask or submit issue.

#18370 report it
myrazel at 2014/10/22 03:58am
Nice extensions!!

So far works good, keep it up

#17965 report it
masdib.banget at 2014/08/19 03:26am
Success

Yes, i make a rule and saved. Usefull. Thanks Misbahul D Munir

#17955 report it
Misbahul D Munir at 2014/08/16 08:42am
@masdib.banget

How do you assign to curkmkd field. as mass assigment or individual assignment? try to add curkmkd to model rules.

contact me at gtalk misbahuldmunir@gmail.com or fb misbahul.d.munir

#17953 report it
masdib.banget at 2014/08/16 03:16am
I was try but not save still 00-00-0000

my models :

public function behaviors()
        {
            return array(
                'AutoDateFormat' => array(
                    'class' => 'ext.MdmAutoDateBehavior',
                    'logicalFormat' => 'd-m-Y', // optional, default d-m-Y
                    'physicalFormat' => 'Y-m-d', // optional, default Y-m-d
                    'attributes' => array(
                        'curkmkd' => 'CUR_KMKD', // mapping attribute from logical to physical filed.
                    ),
                ),
            );
        }

Please tell me, help n correct me.

Leave a comment

Please to leave your comment.

Create extension