简体   繁体   English

TYPO3 Extbase禁忌证日期在域对象模型中

[英]TYPO3 Extbase contrain date in Domain Object Model

I have a model class with start date and end date. 我有一个带有开始日期和结束日期的模型类。 I want to make sure that the start date is always less than the end date. 我想确保开始日期始终小于结束日期。

I thought I might achieve this with an @validate annotation in the model class and a custom validator class like in the docs . 我以为我可以在模型类中使用@validate批注以及在docs中使用自定义验证器类来实现此@validate

How can I get access to the start date value in the validate function? 如何在验证功能中访问开始日期值?

<?php

namespace XXX\YYY\Domain\Model\Validator;

use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator;

class EventEndDateValidator extends AbstractValidator
{
    public function validate($endDate)
    {
       return;
        $this->addError('Validator cant do anything yet.', 42);
    }
}

Even Typo3 doesn't provide This type of functionalities, You can test in start_date and end_date in "Access" in any typo3 default element. 即使Typo3不提供此类功能,您也可以在任何typo3默认元素的“访问”中的start_date和end_date中进行测试。

For this, you should use the hook and compare dates while user save record , and return false with the error message. 为此,您应该使用钩子并在用户保存record时比较日期,并在错误消息中返回false。

Let me know if you need any help related to hook 让我知道您是否需要与挂钩相关的任何帮助

Thanks!! 谢谢!!

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

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