rangelreale/yii2-mdh

Yii2 helper form PHP MDH

Installs: 7

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:yii2-extension

dev-master 2018-03-26 19:42 UTC

This package is not auto-updated.

Last update: 2024-12-21 19:53:00 UTC


README

This library contains helpers for using the Multi Data Handler (MDH) library with Yii2.

Usage

Add the mdh application component to the web.php file.

    'mdh' => [
        'class' => 'app\components\MDH',
    ],

Optionally, you can replace the formatter to the MDH one.

    'formatter' => [
        'class' => 'RangelReale\yii2mdh\Formatter',
    ],

Then you can access MDH using the syntax:

    Yii::$app->mdh->format('user', 'datetime', time());

Using in Yii2 components

Use \RangelReale\yii2mdh\Formatter with the 'converterFrom' property to automatically convert the data from any converter to the 'user'. You can also set the target conververt using the 'converter' property.

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'formatter' => new \RangelReale\yii2mdh\Formatter(['converterFrom'=>'db']),
    'columns' => [
        'id',
        'name',
        [
            'attribute' => 'dt_add',
            'format' => 'datetime',
        ],
        [
            'attribute' => 'dt',
            'format' => 'date',
        ],
        [
            'attribute' => 'tm',
            'format' => 'time',
        ],
        [
            'attribute' => 'is_person',
            'format' => 'boolean',
        ],
        [
            'attribute' => 'duration',
            'format' => 'timeperiod',
        ],
    ],
]);

ArrayDataProvider

This DataProvider automatically converts values between formats.

$dataProvider = new \RangelReale\yii2mdh\ArrayDataProvider([
    'allModels' => $data,
    'key' => 'id',
    'converterFrom' => 'db',
    'converterTo' => 'user,
    'convert' => [
        'dt_add' => 'datetime',
        'dt' => 'date',
        'tm' => 'time',
        'is_user' => 'boolean',
        'duration' => 'timeperiod',
    ],
]);

Author

Rangel Reale