【问题标题】:Zend input Filter in ZF3 - filtering a dateZF3 中的 Zend 输入过滤器 - 过滤日期
【发布时间】:2018-01-05 12:04:50
【问题描述】:

我正在尝试在 ZF3 中将日期过滤器添加到我的表单中。所以在我的 FooForm 中我实现了 InputFilterProviderInterface 并在我的方法中得到了:

public function getInputFilterSpecification()
{
    return [
        'BarInput' => [
            'validators' => [
                [
                    'name' => StringLength::class,
                    'options' => [
                        'min' => 2,
                        'max' => 5,
                    ],
                ],
            ],
            'filters' => [
                [
                    'name' => 'Zend\Filter\Date?'
                ]

所以对于过滤器,我不知道该放什么日期(我检查了文档,但我一无所知)。我的 dateInput 是一个字符串,我想输出一个 \DateTimeImmutable,以便将它正确保存在我的控制器中。

【问题讨论】:

  • 在您的表单中使用Zend\Element\DateZend\Element\DateSelect,它们具有正确的过滤器。
  • 我当然使用 Zend\Element\Date 但 $form->getData()["date"] 是一个字符串,我的学说 orm 模块只接受我在实体中提到的日期对于这个特定的领域。

标签: date zend-framework zend-framework3 zend-inputfilter


【解决方案1】:

我在供应商文件中找到了答案:

'filters' => [
                [
                    'name' => 'Zend\Filter\DatetimeFormatter',
                    'options' => [
                        'format' => 'Y-m-d',
                    ],
                ]
            ]

请注意格式,因为发送的 Chrome 格式与显示的不一样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    • 2020-12-29
    • 2015-08-30
    • 2014-10-20
    • 2013-04-17
    相关资源
    最近更新 更多