The formatting methods provided by Formatter are all named in the form of asXyz(). The behavior of some of them may be configured via the properties of Formatter. For example, by configuring [[dateFormat]], one may control how Formatter::asDate formats the value into a date string. Formatter is configured as an application component in Application by default. You can access that instance via Yii::$app->formatter. The Formatter class is designed to format values according to a [[locale]]. For this feature to work the PHP intl extension has to be installed. Most of the methods however work also if the PHP intl extension is not installed by providing a fallback implementation. Without intl month and day names are in English only.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Author: Enrica Ruedin (e.ruedin@guggach.com)
Author: Carsten Brandt (mail@cebe.cc)
Inheritance: extends yii\base\Component
示例#1
0
 public function testDate()
 {
     $time = time();
     $this->assertSame(date('n/j/y', $time), $this->formatter->asDate($time));
     $this->assertSame(date('F j, Y', $time), $this->formatter->asDate($time, 'long'));
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asDate(null));
 }
示例#2
0
 public function testIntlUtf8Ru()
 {
     $this->assertEquals('d M Y \\г.', FormatConverter::convertDateIcuToPhp('dd MMM y \'г\'.', 'date', 'ru-RU'));
     $this->assertEquals('dd M yy \'г\'.', FormatConverter::convertDateIcuToJui('dd MMM y \'г\'.', 'date', 'ru-RU'));
     $formatter = new Formatter(['locale' => 'ru-RU']);
     $this->assertEquals('24 авг 2014 г.', $formatter->asDate('2014-8-24', 'dd MMM y \'г\'.'));
 }
示例#3
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (Yii::$app->getModule('admin')->settings->get('defaultDateInputFormat') != '') {
         $this->dateInputFormat = Yii::$app->getModule('admin')->settings->get('defaultDateInputFormat');
     }
 }
示例#4
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (Setting::Get('defaultDateInputFormat', 'admin') != '') {
         $this->dateInputFormat = Setting::Get('defaultDateInputFormat', 'admin');
     }
 }
 public function asDate($value, $format = null)
 {
     if ($value == 0) {
         return '-';
     }
     return parent::asDate($value, $format);
 }
示例#6
0
 public function asDate($value, $format = null)
 {
     if ($value instanceof \MongoDate) {
         $value = $value->sec;
     }
     return parent::asDate($value, $format);
 }
 public function testInputUnixTimestamp()
 {
     $this->formatter->defaultTimeZone = 'UTC';
     $timeStamp = 1431907200;
     $this->formatter->timeZone = 'UTC';
     $this->assertEquals('2015-05-18 00:00:00+0000', $this->formatter->asDateTime($timeStamp, 'yyyy-MM-dd HH:mm:ssZ'));
     $this->formatter->timeZone = 'Europe/Berlin';
     $this->assertEquals('2015-05-18 02:00:00+0200', $this->formatter->asDateTime($timeStamp, 'yyyy-MM-dd HH:mm:ssZ'));
     $this->formatter->defaultTimeZone = 'Europe/Berlin';
     $timeStamp = 1431907200;
     $this->formatter->timeZone = 'UTC';
     $this->assertEquals('2015-05-18 00:00:00+0000', $this->formatter->asDateTime($timeStamp, 'yyyy-MM-dd HH:mm:ssZ'));
     $this->formatter->timeZone = 'Europe/Berlin';
     $this->assertEquals('2015-05-18 02:00:00+0200', $this->formatter->asDateTime($timeStamp, 'yyyy-MM-dd HH:mm:ssZ'));
     $this->formatter->defaultTimeZone = 'UTC';
     $timeStamp = -1431907200;
     $this->formatter->timeZone = 'UTC';
     $this->assertEquals('1924-08-17 00:00:00+0000', $this->formatter->asDateTime($timeStamp, 'yyyy-MM-dd HH:mm:ssZ'));
     $this->formatter->timeZone = 'Europe/Berlin';
     $this->assertEquals('1924-08-17 01:00:00+0100', $this->formatter->asDateTime($timeStamp, 'yyyy-MM-dd HH:mm:ssZ'));
     $this->formatter->defaultTimeZone = 'Europe/Berlin';
     $timeStamp = -1431907200;
     $this->formatter->timeZone = 'UTC';
     $this->assertEquals('1924-08-17 00:00:00+0000', $this->formatter->asDateTime($timeStamp, 'yyyy-MM-dd HH:mm:ssZ'));
     $this->formatter->timeZone = 'Europe/Berlin';
     $this->assertEquals('1924-08-17 01:00:00+0100', $this->formatter->asDateTime($timeStamp, 'yyyy-MM-dd HH:mm:ssZ'));
 }
示例#8
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $this->datetimeFormat = 'php:d.m.Y H:i:s';
     $this->dateFormat = 'php:d.m.Y';
     $this->timeFormat = 'php:H:i:s';
     $this->thousandSeparator = ' ';
     parent::init();
 }
示例#9
0
 /**
  * https://github.com/yiisoft/yii2/issues/4960
  */
 public function testAsSizeConfiguration()
 {
     $this->assertSame("1023 bytes", $this->formatter->asSize(1023));
     $this->assertSame("1023 B", $this->formatter->asShortSize(1023));
     $this->formatter->thousandSeparator = '.';
     $this->assertSame("1023 bytes", $this->formatter->asSize(1023));
     $this->assertSame("1023 B", $this->formatter->asShortSize(1023));
 }
示例#10
0
 public function testAsBoolean()
 {
     $this->assertSame('Yes', $this->formatter->asBoolean(true));
     $this->assertSame('No', $this->formatter->asBoolean(false));
     $this->assertSame('Yes', $this->formatter->asBoolean("111"));
     $this->assertSame('No', $this->formatter->asBoolean(""));
     $this->assertSame('No', $this->formatter->asBoolean(0));
     // null display
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asBoolean(null));
 }
示例#11
0
 public function asDatetime($value, $format = null)
 {
     if ($this->calendar->code == 'gregorian') {
         return parent::asDatetime($value, $format);
     }
     if ($format === null) {
         $format = $this->datetimeFormat;
     }
     return $this->formatDateTimeValue($value, $format, 'datetime');
 }
 /**
  * Formats the value as a datetime.
  * @param integer|string|DateTime $value the value to be formatted. The following
  * types of value are supported:
  *
  * - an integer representing a UNIX timestamp
  * - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php).
  *   The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given.
  * - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
  *
  * @param string $format the format used to convert the value into a date string.
  * If null, [[dateFormat]] will be used.
  *
  * This can be 'short', 'medium', 'long', or 'full', which represents a preset format of different lengths.
  * It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime).
  *
  * Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the
  * PHP [date()](http://php.net/manual/de/function.date.php)-function.
  *
  * @return string the formatted result.
  * @throws InvalidParamException if the input value can not be evaluated as a date value.
  * @throws InvalidConfigException if the date format is invalid.
  * @see datetimeFormat
  */
 public function asDatetime($value, $format = null)
 {
     switch ($this->locale) {
         case 'ru':
             return $this->datetimeAsHumanRu($value, $format);
         case 'en':
             return $this->datetimeAsHumanEn($value, $format);
         default:
             return parent::asDatetime($value, $format);
     }
 }
示例#13
0
 /**
  * The same as asRelativeTime, but with overdue highlighting
  * @param $value
  * @param null $referenceTime
  * @return string
  */
 public function asRelativeTimeHighlight($value, $referenceTime = null)
 {
     if ($value === date('Y-m-d')) {
         return Html::tag('span', \Yii::t('app', 'today'), ['class' => 'text-warning']);
     } else {
         $sOut = parent::asRelativeTime($value, $referenceTime);
         if ($value < date('Y-m-d')) {
             $sOut = Html::tag('span', $sOut, ['class' => 'text-danger']);
         }
         return $sOut;
     }
 }
 /**
  * https://github.com/yiisoft/yii2/issues/6263
  *
  * it is a PHP bug: https://bugs.php.net/bug.php?id=45543
  * Fixed in this commit: https://github.com/php/php-src/commit/22dba2f5f3211efe6c3b9bb24734c811ca64c68c#diff-7b738accc3d60f74c259da18588ddc5dL2996
  * Fixed in PHP >5.4.26 and >5.5.10. http://3v4l.org/mlZX7
  *
  * @dataProvider provideTimezones
  */
 public function testIssue6263($dtz)
 {
     $this->formatter->defaultTimeZone = $dtz;
     $this->formatter->timeZone = 'UTC';
     $this->assertEquals('24.11.2014 11:48:53', $this->formatter->format(1416829733, ['date', 'php:d.m.Y H:i:s']));
     $this->formatter->timeZone = 'Europe/Berlin';
     $this->assertEquals('24.11.2014 12:48:53', $this->formatter->format(1416829733, ['date', 'php:d.m.Y H:i:s']));
     $this->assertFalse(DateTime::createFromFormat('Y-m-d', 1416829733));
     $this->assertFalse(DateTime::createFromFormat('Y-m-d', '2014-05-08 12:48:53'));
     $this->assertFalse(DateTime::createFromFormat('Y-m-d H:i:s', 1416829733));
     $this->assertFalse(DateTime::createFromFormat('Y-m-d H:i:s', '2014-05-08'));
 }
示例#15
0
 /**
  * Generates the static input
  *
  * @param string $type the static input type.
  * @param Model $model the data model.
  * @param integer $index the zero based index of the item in dataProvider.
  * @param array $settings the attribute settings.
  * @param string $attribute the attribute.
  * @param Formatter $formatter the formatter instance.
  *
  * @return string the generated static input.
  */
 protected function getStaticInput($type, $model, $index, $settings, $attribute, $formatter)
 {
     $format = ArrayHelper::getValue($settings, 'format', 'raw');
     if ($type === self::INPUT_HIDDEN_STATIC) {
         $options = ArrayHelper::getValue($settings, 'hiddenStaticOptions', []);
     } else {
         $options = ArrayHelper::getValue($settings, 'options', []);
     }
     $val = null;
     if (isset($settings['staticValue'])) {
         $val = $settings['staticValue'];
     } else {
         if (isset($settings['value'])) {
             $val = $settings['value'];
         } elseif ($model instanceof Model) {
             $val = Html::getAttributeValue($model, $attribute);
         } elseif (($models = $this->dataProvider->getModels()) && !empty($models[$index][$attribute])) {
             $val = $models[$index][$attribute];
         }
     }
     $val = $formatter->format($val, $format);
     $prepend = ArrayHelper::getValue($settings, 'prepend', '');
     $append = ArrayHelper::getValue($settings, 'append', '');
     $val = $prepend . "\n" . $val . "\n" . $append;
     Html::addCssClass($options, 'form-control-static');
     return Html::tag('div', $val, $options);
 }
示例#16
0
<?php

/**
 * mobiles
 * Created: 18.02.16 14:40
 * @copyright Copyright (c) 2016 OSKR NIAEP
 */
/**
 * @var  \yii\data\ActiveDataProvider $dataProvider
 */
?>

<?php 
echo \yii\grid\GridView::widget(['dataProvider' => $dataProvider, 'tableOptions' => ['class' => 'table table-hover'], 'formatter' => ['class' => \yii\i18n\Formatter::className(), 'nullDisplay' => '-'], 'columns' => ['number', 'employee', 'limit', 'expenditure', ['attribute' => 'overrun', 'content' => function ($model) {
    return is_null($model['overrun']) ? 0 : $model['overrun'];
}], 'comment']]);
示例#17
0
<?php 
$this->title = 'База номеров';
?>

    <div id="mobileNumberIndexView">

        <?php 
echo Html::pageHeader($this->title);
?>

        <?php 
echo $this->render('_search', ['model' => $searchModel]);
?>

        <?php 
echo ExportMenu::widget(['dataProvider' => $exportDataProvider, 'exportConfig' => [ExportMenu::FORMAT_PDF => false], 'target' => ExportMenu::TARGET_SELF, 'showConfirmAlert' => false, 'formatter' => ['class' => \yii\i18n\Formatter::className(), 'nullDisplay' => ''], 'columns' => ['number', ['label' => 'Сотрудник', 'content' => function ($model) {
    return $model->owner ? $model->owner->fullName : "";
}], 'comment'], 'filename' => 'База сотовых номеров']);
?>

        <?php 
Pjax::begin(['formSelector' => 'form#numberSearchForm', 'id' => 'pjaxContainerForGridView']);
?>

        <?php 
echo $this->render('_gridview', ['dataProvider' => $dataProvider]);
?>

        <?php 
Pjax::end();
?>
 public function testOneDigitIcu()
 {
     $formatter = new Formatter(['locale' => 'en-US']);
     $this->assertEquals('24.8.2014', $formatter->asDate('2014-8-24', 'php:d.n.Y'));
     $this->assertEquals('24.8.2014', $formatter->asDate('2014-8-24', 'd.M.yyyy'));
 }
 /**
  * Formats the value as a date.
  * @param integer|string|DateTime $value the value to be formatted. The following
  * types of value are supported:
  *
  * - an integer representing a UNIX timestamp
  * - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php).
  *   The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given.
  * - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
  *
  * @param string $format the format used to convert the value into a date string.
  * If null, [[dateFormat]] will be used.
  *
  * This can be "short", "medium", "long", or "full", which represents a preset format of different lengths.
  * It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime).
  *
  * Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the
  * PHP [date()](http://php.net/manual/en/function.date.php)-function.
  *
  * @return string the formatted result.
  * @throws InvalidParamException if the input value can not be evaluated as a date value.
  * @throws InvalidConfigException if the date format is invalid.
  * @see dateFormat
  */
 public function asDate($value, $format = null)
 {
     if ($format == 'human') {
         switch ($this->locale) {
             case 'ru':
                 return $this->datetimeAsHumanRu($value, false);
                 break;
             case 'en':
                 return $this->datetimeAsHumanEn($value, false);
                 break;
         }
     }
     return parent::asDate($value, $format);
 }
 /**
  * @inheritdoc
  */
 public function getFormatter()
 {
     $this->preProcessConfigurableItem('formatter', Formatter::className());
     return $this->formatter;
 }
示例#21
0
use romkaChev\yandexFotki\models\AlbumPhotosCollection;
use romkaChev\yandexFotki\models\AlbumsCollection;
use romkaChev\yandexFotki\models\Author;
use romkaChev\yandexFotki\models\Image;
use romkaChev\yandexFotki\models\options\album\CreateAlbumOptions;
use romkaChev\yandexFotki\models\options\album\DeleteAlbumOptions;
use romkaChev\yandexFotki\models\options\album\GetAlbumPhotosOptions;
use romkaChev\yandexFotki\models\options\album\GetAlbumsOptions;
use romkaChev\yandexFotki\models\options\album\UpdateAlbumOptions;
use romkaChev\yandexFotki\models\options\photo\CreatePhotoOptions;
use romkaChev\yandexFotki\models\options\photo\DeletePhotoOptions;
use romkaChev\yandexFotki\models\options\photo\UpdatePhotoOptions;
use romkaChev\yandexFotki\models\options\tag\DeleteTagOptions;
use romkaChev\yandexFotki\models\options\tag\GetTagPhotosOptions;
use romkaChev\yandexFotki\models\options\tag\UpdateTagOptions;
use romkaChev\yandexFotki\models\Photo;
use romkaChev\yandexFotki\models\Point;
use romkaChev\yandexFotki\models\Tag;
use romkaChev\yandexFotki\models\TagPhotosCollection;
use romkaChev\yandexFotki\validators\AddressBindingValidator;
use romkaChev\yandexFotki\validators\AlbumValidator;
use romkaChev\yandexFotki\validators\AuthorValidator;
use romkaChev\yandexFotki\validators\ImageValidator;
use romkaChev\yandexFotki\validators\PhotoValidator;
use romkaChev\yandexFotki\validators\PointValidator;
use romkaChev\yandexFotki\validators\TagValidator;
use romkaChev\yandexFotki\YandexFotki;
use yii\httpclient\Client;
use yii\i18n\Formatter;
return ['id' => 'testApp', 'basePath' => __DIR__, 'vendorPath' => __DIR__ . '/../../../vendor', 'aliases' => ['@web' => '/', '@webroot' => __DIR__ . '/../runtime', '@vendor' => __DIR__ . '/../../../vendor'], 'components' => ['yandexFotki' => ['class' => YandexFotki::className(), 'apiBaseUrl' => 'http://api-fotki.yandex.ru/api', 'serviceBaseUrl' => 'http://fotki.yandex.ru', 'login' => null, 'oauthToken' => null, 'apiHttpClient' => Client::className(), 'serviceHttpClient' => Client::className(), 'albums' => AlbumComponent::className(), 'photos' => PhotoComponent::className(), 'tags' => TagComponent::className(), 'formatter' => Formatter::className(), 'factory' => ['class' => Factory::className(), 'addressBindingModel' => AddressBinding::className(), 'albumModel' => Album::className(), 'albumsCollectionModel' => AlbumsCollection::className(), 'albumPhotosCollectionModel' => AlbumPhotosCollection::className(), 'authorModel' => Author::className(), 'photoModel' => Photo::className(), 'tagModel' => Tag::className(), 'tagPhotosCollectionModel' => TagPhotosCollection::className(), 'pointModel' => Point::className(), 'imageModel' => Image::className(), 'getAlbumsOptions' => GetAlbumsOptions::className(), 'getAlbumPhotosOptions' => GetAlbumPhotosOptions::className(), 'createAlbumOptions' => CreateAlbumOptions::className(), 'updateAlbumOptions' => UpdateAlbumOptions::className(), 'deleteAlbumOptions' => DeleteAlbumOptions::className(), 'createPhotoOptions' => CreatePhotoOptions::className(), 'updatePhotoOptions' => UpdatePhotoOptions::className(), 'deletePhotoOptions' => DeletePhotoOptions::className(), 'getTagPhotosOptions' => GetTagPhotosOptions::className(), 'updateTagOptions' => UpdateTagOptions::className(), 'deleteTagOptions' => DeleteTagOptions::className(), 'addressBindingValidator' => AddressBindingValidator::className(), 'albumValidator' => AlbumValidator::className(), 'authorValidator' => AuthorValidator::className(), 'pointValidator' => PointValidator::className(), 'photoValidator' => PhotoValidator::className(), 'imageValidator' => ImageValidator::className(), 'tagValidator' => TagValidator::className()]]]];
示例#22
0
 /**
  * Converts relational object to DetailView structure
  * @return array
  */
 public function getDetailViewProfileData()
 {
     $profileFields = array_keys($this->profileFields);
     $excludeFields = ['name'];
     $data = [];
     if (!empty($profileFields) && $this->profileModel !== null) {
         foreach ($profileFields as $name) {
             if (!in_array($name, $excludeFields) && isset($this->profileModel->{$name}) && !empty($this->profileModel->{$name}) && is_scalar($this->profileModel->{$name})) {
                 switch ($this->profileFields[$name]['field_type']) {
                     case 'date':
                         $format = new Formatter();
                         $data[] = ['attribute' => "profileModel.{$name}", 'label' => $this->profileFields[$name]['label'], 'format' => 'html', 'value' => '<abbr title="' . $this->profileModel->{$name} . '">' . $format->format($this->profileModel->{$name}, 'RelativeTime') . '</abbr>'];
                         break;
                     case 'url':
                         $data[] = ['attribute' => "profileModel.{$name}", 'label' => $this->profileFields[$name]['label'], 'format' => 'raw', 'value' => Html::a($this->profileModel->{$name}, $this->profileModel->{$name}, ['target' => '_blank'])];
                         break;
                     default:
                         $data[] = ['attribute' => "profileModel.{$name}", 'label' => $this->profileFields[$name]['label'], 'value' => $this->profileModel->{$name}];
                         break;
                 }
             }
         }
     }
     return $data;
 }
示例#23
0
                    <?php 
ContainerLoader::end();
?>
                </ul>
            </div>
        </div>
    </div>

<?php 
echo Html::a("Назад", 'javascript:history.go(-1)', ['class' => "btn btn-primary"]);
?>

    <div>

        <p class="h3"><?php 
echo $model->header();
?>
</p>

        <?php 
echo ExportMenu::widget(['dataProvider' => $model->itemsDataProvider(), 'columns' => $model->itemsColumns(), 'target' => ExportMenu::TARGET_SELF, 'showConfirmAlert' => false, 'formatter' => ['class' => \yii\i18n\Formatter::className(), 'nullDisplay' => '', 'decimalSeparator' => ',', 'thousandSeparator' => ''], 'filename' => $model->header(), 'exportConfig' => [ExportMenu::FORMAT_HTML => false, ExportMenu::FORMAT_PDF => false]]);
?>

        <?php 
echo GridView::widget(['dataProvider' => $model->itemsDataProvider(), 'columns' => $model->itemsColumns(), 'formatter' => ['class' => \yii\i18n\Formatter::className(), 'nullDisplay' => ''], 'tableOptions' => ['class' => 'table table-striped table table-hover']]);
?>

    </div>

<?php 
echo Html::a("Назад", 'javascript:history.go(-1)', ['class' => "btn btn-primary"]);
 /**
  * Возвращает список месяцев
  *
  * @param bool $declension
  * @return array
  */
 public static function getMonthsList($declension = false)
 {
     $_months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
     $months = [];
     if (!$declension) {
         foreach ($_months as $key => $month) {
             $months[++$key] = Yii::t('basis', $month);
         }
         return $months;
     }
     $formatter = new Formatter();
     foreach ($_months as $key => $month) {
         $months[++$key] = $formatter->asDate($month, 'php:F');
     }
     return $months;
 }
示例#25
0
 /**
  * @inheritdoc
  * Adds support for [-]infinity.
  */
 public function asDatetime($value, $format = null)
 {
     if (($label = $this->isInfinity($value)) !== null) {
         return $label;
     }
     return parent::asDatetime($value, $format);
 }
示例#26
0
 /**
  * @return Formatter formatter instance
  */
 public function getFormatter()
 {
     if (!is_object($this->_formatter)) {
         if ($this->_formatter === null) {
             $this->_formatter = Yii::$app->getFormatter();
         } else {
             $this->_formatter = Instance::ensure($this->_formatter, Formatter::className());
         }
     }
     return $this->_formatter;
 }
示例#27
0
 /**
  * @inheritdoc
  */
 public function asDatetime($value, $format = null)
 {
     return str_replace(['January', 'February', 'Match', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], ['янв', 'фев', 'мар', 'апр', 'мая', 'июн', 'июль', 'авг', 'сен', 'окт', 'ноя', 'дек'], parent::asDatetime($value, $format));
 }
示例#28
0
文件: Formatter.php 项目: vsguts/crm
 public function asDatetimeFiltered($value, $format = null)
 {
     return $value ? parent::asDatetime($value, $format) : null;
 }
示例#29
0
    $base['components']['user'] = ['class' => 'canis\\web\\User', 'enableAutoLogin' => false, 'identityClass' => 'cascade\\server\\models\\User', 'loginUrl' => ['/user/login']];
}
if (!isset($base['components']['fileStorage'])) {
    $base['components']['fileStorage'] = ['class' => FileStorage::className()];
}
if (!isset($base['components']['view'])) {
    $base['components']['view'] = ['class' => View::className()];
}
if (!isset($base['components']['response'])) {
    $base['components']['response'] = ['class' => Response::className()];
}
if (!isset($base['components']['log'])) {
    $base['components']['log'] = [];
}
if (!isset($base['components']['log']['traceLevel'])) {
    $base['components']['log']['traceLevel'] = YII_DEBUG ? 3 : 0;
}
if (!isset($base['components']['log']['targets'])) {
    $base['components']['log']['targets'] = [];
    $base['components']['log']['targets'][] = ['class' => FileTarget::className(), 'levels' => ['error', 'warning']];
}
if (!isset($base['components']['formatter'])) {
    $base['components']['formatter'] = ['class' => I18nFormatter::className(), 'dateFormat' => 'MM/dd/yyyy'];
}
if (YII_DEBUG) {
    if (!isset($base['components']['errorHandler'])) {
        $base['components']['errorHandler'] = [];
    }
    $base['components']['errorHandler']['discardExistingOutput'] = false;
}
return $base;
示例#30
0
 public function asDateTime($value, $format = 'human')
 {
     if ($format == 'human') {
         $dStart = new \DateTime($value);
         $dEnd = new \DateTime();
         return $this->formatDateDiff($dStart, $dEnd);
     } else {
         parent::asDateTime($value, $format);
     }
 }