Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2:Date Application Formatter

Tags:

php

datetime

yii2

I am using Yii::$app->formatter in one of my attribute like:

Controller code

$model->discharge_date=Yii::$app->formatter->asDatetime
($model->discharge_date, 'php:d-M-Y H:i');

Model Code

[['admission_date','discharge_date'],'date','format' => 'php:d-M-Y H:i'],

Everything is working fine except when discharge date is left blank, on update it is filled with this line:

<span class="not-set">(not set)</span>

I couldn't make out from where this is coming, as in the DB the value is NUll

Thanks.

like image 703
Pawan Avatar asked Apr 02 '15 08:04

Pawan


1 Answers

It's default and expected behavior.

See documentation for $nullDisplay property of Formatter.

You can cnahge that across application through application configuration:

'formatter' => [
    'nullDisplay' => '',
],

For specific view you can change it through formatter component (note that you should add that code before view is rendered):

use Yii;

...

Yii::$app->formatter->nullDisplay = '';
like image 126
arogachev Avatar answered Oct 20 '22 21:10

arogachev