简体   繁体   English

TYPO3-TCA-日期时间格式

[英]TYPO3 - TCA - Datetimeformat

Typo3 6.2, working on my personal extension. Typo3 6.2,正在我的个人扩展上。 I'm using a flexform with this TCA : 我在此TCA中使用了flexform:

'eventdate' => array(
    'exclude' => 1,
    'label' => 'Date of event :',
    'config' => array(
        'type' => 'input',
        'size' => 30,
        'eval'     => 'datetime',
        'checkbox' => '0',
        'default'  => time(),
    ),
),

... and my SQL field is a DATETIME, sample from my ext_tables.sql : ...而我的SQL字段是DATETIME,来自我的ext_tables.sql示例:

CREATE TABLE xxxxxxx
(
    eventdate DATETIME NOT NULL,
);

Problem : when saving, the generated field format by Typo3 is hh:mm:ss dd:mm:yyyy but in my SQL table the datetime format is yyyy-mm-dd hh:mm:ss , then it makes an error when user try to save in the backend : 问题:保存时,由Typo3生成的字段格式为hh:mm:ss dd:mm:yyyy,但是在我的SQL表中,日期时间格式为yyyy-mm-dd hh:mm:ss ,然后在用户尝试时会出错保存在后端:

1: These fields are not properly updated in database: (eventdate) Probably value mismatch with fieldtype. 1:数据库中的这些字段未正确更新:(事件日期)可能与字段类型的值不匹配。

How to resolve this issue ? 如何解决这个问题?

I think int DATA TYPE is the best way to store DATE in tstamp format in DB. 我认为int DATA TYPE是在数据库中以tstamp格式存储DATE的最佳方法。

You need to define eventdate DATA TYPE like below 您需要定义如下的eventdate DATA TYPE

CREATE TABLE xxxxxxx
(
    eventdate int(11) unsigned DEFAULT '0' NOT NULL,
);

The TCA configuration of the original question misses the dbType property which instructs TYPO3 during saving data in DataHandler to use a different time format (the default format is unix timestamp which is normalized to UTC). 原始问题的TCA配置dbType属性,该属性指示TYPO3在将数据保存到DataHandler中时使用不同的时间格式(默认格式为unix timestamp,已标准化为UTC)。

See https://docs.typo3.org/typo3cms/TCAReference/7.6/Reference/Columns/Input/#dbtype for details (the documentation is for TYPO3 7.6 but worked since TYPO3 6.0 as well). 有关详细信息,请参见https://docs.typo3.org/typo3cms/TCAReference/7.6/Reference/Columns/Input/#dbtype (该文档适用于TYPO3 7.6,但自TYPO3 6.0起也可以使用)。

ext_tables.sql ext_tables.sql

CREATE TABLE tx_myextension_xxxxxxx (
   eventdate DATETIME default NULL
)

TCA field configuration TCA现场配置

'eventdate' => array(
    'exclude' => 1,
    'label' => 'Date of event:',
    'config' => array(
        'type' => 'input',
        'size' => 30,
        'eval'     => 'datetime',
        'dbType'   => 'datetime',
        'default'  => date('Y-m-d H:i:s'),
    ),
),
  • removed checkbox which is superfluous for type input 删除了对于类型input来说多余的checkbox
  • adjusted default value to date('Ymd H:i:s') 调整为date('Ymd H:i:s')默认值date('Ymd H:i:s')
  • added dbType property 添加了dbType属性

Side note for TYPO3 v8 TYPO3 v8的旁注

See https://docs.typo3.org/typo3cms/TCAReference/8.7/ColumnsConfig/Type/Input.html#rendertype-inputdatetime which shows the new render type for datetime values that can be used in TYPO3 v8. 请参阅https://docs.typo3.org/typo3cms/TCAReference/8.7/ColumnsConfig/Type/Input.html#rendertype-in​​putdatetime ,其中显示了可在TYPO3 v8中使用的datetime值的新渲染类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM