简体   繁体   中英

TYPO3 9 LTS type casting error on mysql time field for TCA type input / dbType time saving empty field

I'm trying to have a time input in TYPO3 9 LTS working together with MySQL 5.7.24.

In the ext_tables.sql the field gets defined like this:

some_field time default NULL

In the TCA the field gets defined like this:

  'some_field' => [
    'exclude' => 1,
    'label' => 'Some field',
    'config' => [
      'type' => 'input',
      'dbType' => 'time',
      'eval' => 'time',
    ],
  ],

When saving the record in the backend without a time input (which should be possible) I'm getting the error:

These fields of record 1 in table "some_table" have not been saved correctly: some_field! The values might have changed due to type casting of the database.

When looking at the database record the some_field field gets the value 00:00:00 (although the db default is NULL ).

When selecting a time the record can be saved and opened without error.

Is this a bug in TYPO3 or how could I fix this behavior?

That means you have given the wrong type for the value on your ext_tables.sql. Additionally, TYPO3 v9 has renderTypes . Try something like that:

ext_tables.sql

begin int(11) DEFAULT '0' NOT NULL

TCA

'begin' => [
   'exclude' => true,
   'label' => 'LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tx_yourext_domain_model_modelname.begin',
   'config' => [
        'type' => 'input',
        'renderType' => 'inputDateTime',
         'size' => 10,
         'eval' => 'datetime',
         'default' => time()
     ],
],

Additional information!

If you want to display the time in FrontEnd you could use something like that

<f:format.date>{dateObject.begin}</f:format.date>

If you want to modify how it looks, you can use the format attribute as well:

<f:format.date format="%d. %B %Y">{dateObject.begin}</f:format.date>

More about that here: TYPO3 Date format

该错误可以通过以下eval来解决:

'eval' => 'time,null',

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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