Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 749 Bytes

CorrectDateBehavior.md

File metadata and controls

40 lines (30 loc) · 749 Bytes

CorrectDateBehavior

This extension will help you to convert dates and unixtime to text format and Vice versa

Using

$model = new News();

$model->date_from = 1524775512;
echo $model->dateFrom; // 26.04.2018 20:45:12

$model->dateFrom = '01.05.2018';
echo $model->date_from; // 1515110400

Configuration

use lav45\behaviors\CorrectDateBehavior;

class News extends Model
{
    public function behaviors()
    {
        return [
            [
                'class' => CorrectDateBehavior::class,
                // 'format' => 'datetime',
                'attributes' => [
                    'dateFrom' => 'date_from',
                    'dateTo' => 'date_to',
                ]
            ]
        ];
    }
}