formatter = class = yiii18nFormatter timeZone = AsiaShanghai 在 backendconfigmainphp中设置无法改变debugtoolbar的时区显示
要更改debugtoolbar的时区显示,您需要在yii\debug\Panel类中覆盖getTime()方法。例如,您可以在common/components/DebugPanel.php中创建一个新的类,它继承自yii\debug\Panel,并覆盖getTime()方法:
namespace common\components;
use Yii;
use yii\debug\Panel;
class DebugPanel extends Panel
{
public function getTime()
{
$time = parent::getTime();
$formatter = Yii::$app->formatter;
$time = $formatter->asDatetime($time, 'medium');
$time = $formatter->asTime($time, 'short');
return $time;
}
}
然后,您需要在backend/config/main.php中配置debug组件,以使用新的DebugPanel类:
'bootstrap' => ['debug'],
'components' => [
'debug' => [
'class' => 'yii\debug\Module',
'panels' => [
'time' => [
'class' => 'common\components\DebugPanel',
],
],
],
],
现在,当您在debugtoolbar中查看页面时,它将使用您在Yii::$app->formatter中设置的时区
原文地址: https://www.cveoy.top/t/topic/c9hd 著作权归作者所有。请勿转载和采集!