et-innovations / silverstripe-localdatetime
为 SilverStripe 定制的本地化日期、时间和日期时间字段
dev-master
2022-03-28 09:57 UTC
Requires
- silverstripe/framework: ^3.2
This package is not auto-updated.
Last update: 2024-09-18 23:16:51 UTC
README
可翻译的字段类型包括
- 日期
- 时间
- 日期时间
维护者联系方式
- Hernold Koch hernold.koch@et-innovations.org
需求
- SilverStripe 3.0
安装
通过 composer 安装 composer require et-innovations/silverstripe-localdatetime
或将此存储库的内容提取到项目的根目录。
使用概述
简单地在数组 $db
中创建所需的字段
class MyDataObject extends DataObject {
public static $db = array(
'SomeDateField' => "LocalDate",
'SomeTimeField' => "LocalTime",
'SomeDateTimeField' => "LocalDatetime",
);
}
要在 GridField 中获取翻译值,需要声明一个与字段同名的函数,并返回所需的值
class MyDataObject extends DataObject {
...
public function SomeDateField() {
if($this->{__FUNCTION__})
return DBField::create_field('LocalDate', $this->{__FUNCTION__})->Nice();
}
}