Pawan
Pawan

Reputation: 3864

Yii2:Date Application Formatter

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.

Upvotes: 9

Views: 683

Answers (1)

arogachev
arogachev

Reputation: 33538

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 = '';

Upvotes: 5

Related Questions