This library contains helpers for using the Multi Data Handler (MDH) library with Yii2.
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());
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',
],
],
]);
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',
],
]);
Rangel Reale