简体   繁体   English

TYPO3 日期问题

[英]TYPO3 date issue

I'm a new user of TYPO3 and I'm creating a simple extension for registering data in backend and for display them.我是 TYPO3 的新用户,我正在创建一个简单的扩展来在后端注册数据并显示它们。

I have two date fields with which we can choose dates ourselves to determine the duration of an event by example startDate and endDate我有两个日期字段,我们可以自己选择日期来确定事件的持续时间,例如 startDate 和 endDate

However, when I display the elements saved thanks to my extension, it does not display the date on the date entered, but on today's date.但是,当我显示由于我的扩展而保存的元素时,它不会显示输入日期的日期,而是显示今天的日期。

In database, the date is recorded in UNIX format but with the right values, for example I entered this date: 21-01-2022 and it records 1642806000 in database在数据库中,日期以 UNIX 格式记录,但具有正确的值,例如我输入了这个日期:21-01-2022,它在数据库中记录了 1642806000

I don't know why I have this problem, you think it is a configuration problem?不知道为什么会出现这个问题,你认为是配置问题吗?

Here is some snippet of code:这是一些代码片段:

TCA三氯乙酸

'startDate' => [
            'label' => 'start date',
            'config' => [
                'type' => 'input',
                'renderType' => 'inputDateTime',
                'eval' => 'date',
                ],
        ],
        'endDate' => [
            'label' => 'end',
            'config' => [
                'type' => 'input',
                'renderType' => 'inputDateTime',
                'eval' => 'date',
            ],
        ],

ext_tables.sql ext_tables.sql

  startDate int(11) NOT NULL,
   endDate int(11) NOT NULL,

Model Model

 /**
     * @return \DateTime
     */
    public function getStartDate()
    {
        return $this->startDate;
    }

    /**
     * @param \DateTime $startDate
     */
    public function setStartDate($startDate)
    {
        $this->startDate = $startDate;
    }

    /**
     * @return \DateTime
     */
    public function getEndDate()
    {
        return $this->endDate;
    }

    /**
     * @param \DateTime $endDate
     */
    public function setEndDate($endDate)
    {
        $this->endDate = $endDate;
    }

HTML HTML

<f:format.date format="d.m.Y">{event.startDate}</f:format.date>

Thanks you for your help谢谢你的帮助

i'm using TYPO3 10.4我正在使用 TYPO3 10.4

You need to use underscores in SQL, therefor the mapping is not working.您需要在 SQL 中使用下划线,因此映射不起作用。 Extbase expects a SQL field named start_date when you use startDate in your model.当您在 model 中使用startDate时,Extbase 需要一个名为start_date的 SQL 字段。

It's quite hidden in the Extbase Docs, but I found it (and will change it to be more prominent): https://docs.typo3.org/m/typo3/book-extbasefluid/main/en-us/6-Persistence/1-prepare-the-database.html#preparing-the-tables-of-the-domain-objects它在 Extbase Docs 中非常隐藏,但我发现了它(并将将其更改为更加突出): https://docs.typo3.org/m/typo3/book-extbasefluid/main/en-us/6-Persistence /1-prepare-the-database.html#preparing-the-tables-of-the-domain-objects

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

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