使用zend-filter

时间:2019-03-19 07:10:06

标签: validation zend-framework zend-form zend-filter

zend-filter中,是否可以根据其他字段的值来更改字段的值?在zend-validator中,有一个名为Identical的验证器,does exactly this使验证器的这个过程变得微不足道,但是到目前为止,我还没有找到在过滤器中获取上下文的任何方法。

代码示例:

class SomeFilter extends InputFilter
{
    public function __construct()
    {
        $this->add([
            'name' => 'option1',
            'filters' => [
                new StringTrim(),
                new ToNull(),
            ],
        ]);
        $this->add([
            'name' => 'option2',
            'filters' => [
                new StringTrim(),
                new ToNull(),
                // TODO: Make value null if option1 is not null
            ],
        ]);
    }
}

以上示例的注释中是否有任何方法可以完成功能?如果没有,最优雅的解决方法是什么?现在看来,在包含表单上运行isValid()之后,必须进行手动更正,而这并不是zend-filter的意图。

0 个答案:

没有答案