承接 asmoday74/yii2-timezone 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

asmoday74/yii2-timezone

最新稳定版本:1.0.2

Composer 安装命令:

composer require asmoday74/yii2-timezone

包简介

This component allows you to automatically determine the temporary zone of the user and set it up in the YII2 settings for the correct operation of temporary representations.

README 文档

README

This component allows you to automatically determine the temporary zone of the user and set it up in the YII2 settings for the correct operation of temporary representations.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist asmoday74/yii2-timezone "*"

or add

"asmoday74/yii2-timezone": "*"

to the require section of your composer.json file.

Usage

As soon as the component is installed, add the following config to the application settings (web.php for the template "basic", main.php for the "advanced" template):

$config = [
    ...
    'bootstrap' => ['log', 'timezone'],
    ...
    'components' => [
        ...
        'timezone' => [
            'class' => asmoday74\timezone\UserTimezone::class,
            'controllerName' => 'timezone', //this is default name
            'defaultTimezone' => 'Europe/Moscow'
        ],
        ...
];

Additional information

For the correct work with the time received from the database and saved in it, it is recommended to configure the time ward UTC when connecting to the database. For this:

  • In PostgreSQL:
return [
	'class' => \yii\db\Connection::class,
	'dsn' => 'pgsql:host=localhost;dbname=dbname',
	'username' => 'user',
	'password' => 'password',
	'charset' => 'utf8',
	'on afterOpen' => function($event) {
	    $event->sender->createCommand("SET timezone TO 'UTC'")->execute();
	}
];
  • In MySQL:
return [
	'class' => \yii\db\Connection::class,
	'dsn' => 'mysql:host=localhost;dbname=dbname',
	'username' => 'user',
	'password' => 'password',
	'charset' => 'utf8',
	'on afterOpen' => function($event) {
	    $event->sender->createCommand("SET @@session.time_zone = '+00:00'")->execute();
	}
];

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-09