yii2 0 資料格式器

2021-09-26 05:03:40 字數 1739 閱讀 4339

//格式化日期 august 15,2019

echo $formatter->asdate('2019-08-15','long');

echo $formatter->format('2019-08-15','date');

echo $formatter->astime('2019-08-15 10:10:20 asia/shanghai');//時區

//格式化為百分比12.5%

echo $formatter->aspercent(0.125,2);

echo $formatter->format(0.125,['percent',2]);

//格式化email [email protected]

echo $formatter->asemail('[email protected]');

//格式化布林型別 true->yes false->no

echo $formatter->asboolean(false);

//引數為null 返回not set

echo $formatter->asdate(null);

//格式化貨幣 ¥100.00 不需要 php intl擴充套件

echo $formatter->ascurrency(100);

//將值格式化為數字的序數值。 開啟php intl擴充套件

$d = $formatter->asordinal($formatter->asdate('2017-05-15', 'php:j'));

echo "on the $d day of the month.";

//格式化為整形 返回1

echo $formatter->format(1.2,['integer']);

配置formatter

return [

'dateformat' => 'dd-mm-yyyy',//日期格式

'decimalseparator' => '.',//小數點

'thousandseparator' => ',',//千分位

'currencycode' => 'eur',//貨幣碼

];

日期格式快捷方式

short:將輸出日期 06/10/2014 和時間 15:58;

medium:將輸出 6 oct 2014 和 15:58:42;

long:將輸出 6 october 2014 和 15:58:42 gmt;

full:將輸出 monday, 6 october 2014 和 15:58:42 gmt。

數字格式化

integer: 這個變數將被格式化為整形 e.g. 42.

例如:2,542.123 或 2.542,123。

percent: 這個變數將被格式化為百分比 e.g. 42%.

scientific: 這個變數將被格式化為科學計數法 e.g. 4.2e4.

例如:£420.00。 使用這個方法前請確認是否已經正確配置 locale

size: 這個變數將被格式化為人類可讀的位元組數 e.g. 410 kibibytes.

shortsize: 這個變數將被格式化為人類可讀的位元組數(縮寫) size,例如:410 kib。

如上所述,格式化應用程式可以使用當前有效的 locale 來確定 如何格式化適用於目標國家/地區的值。 例如,對於不同的區域設定,相同的日期可能會有不同的格式:

yii 2 0 寫入日誌

首先,我們的 web.php 配置檔案中,更改於下 log tracelevel yii debug 3 0,targets class yii log filetarget levels error warning trace 在 levels 中,增加了 trace,使用如下 yii trace...

yii 2 0 寫入日誌

首先,我們的 web.php 配置檔案中,更改於下 log tracelevel yii debug 3 0,targets class yii log filetarget levels error warning trace 在 levels 中,增加了 trace,使用如下 yii trace...

yii2 0框架報錯

在action中執行echo,var dump等方法後沒有中斷,yii1.0中ajax方法返回資料可以直接通過echo獲取,但是yii2.0的response類中增加了對於返回輸出資訊的定義,所以當echo後沒有中斷程式,yii自帶的 就會出錯,不過目前我發現的情況是,只有在返回的資料結構複雜的情況...