yii2-format-converter Format converter

  1. Installation
  2. Usage
  3. Resources

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist mdmsoft/yii2-format-converter "*"

or add ~~~ "mdmsoft/yii2-format-converter": "*" ~~~ to the require section of your composer.json file.

Usage

Once the extension is installed, simply modify your ActiveRecord class:

public function behaviors()
{
    return [
        [
            'class' => 'mdm\converter\DateConverter',
            'logicalFormat' => 'd/m/Y', // your readeble datetime format, default to 'd-m-Y'
            'physicalFormat' => 'Y-m-d', // database level format, default to 'Y-m-d'
            'attributes' => [
                'salesDate' => 'sales_date', // sales_date is original attribute
            ]
        ],
        ...
    ]
}

then add attribute salesDate to your model rules.

// in view view.php
echo DetailView::widget([
    'options' => ['class' => 'table table-striped detail-view', 'style' => 'padding:0px;'],
    'model' => $model,
    'attributes' => [
        'sales_num',
        'idSupplier.nm_supplier',
        'salesDate', // use attribute 'salesDate' instead of 'sales_date'
        'nmStatus',
    ],
]);


// in view _form.php 
echo $form->field($model, 'salesDate') // use attribute 'salesDate' instead of 'sales_date'
    ->widget('yii\jui\DatePicker', [
        'options' => ['class' => 'form-control', 'style' => 'width:50%'],
        'clientOptions' => [
            'dateFormat' => 'dd/mm/yy', 
        ],
]);

Resources

0 0
3 followers
0 downloads
Yii Version: 2.0
License: BSD-2-Clause
Category: Database
Developed by: Misbahul D Munir
Created on: Jun 25, 2014
Last updated: 3 years ago

Related Extensions