doujue6196 2015-07-06 10:01
浏览 26

在发布bar [0] [foo] ='xyz'时,ZF2的自定义验证器的$ context突然显示'bar'=> array()

I have a custom validator using $context that has been working for over a year.

The $context contains all posted parameters except for "bar" which is an empty array although it is posted as bar[0][description]. The array used to contain one or more arrays with key-value-pairs.

This seems to be the case since updating from version 2.3.2 to 2.5.1

I can't even check the 2.5 documentation since it's not available, Google didn't turn up anything close to the issue, ... was the behaviour changed or is this a bug?

Edit:

In .../Lorem/Form/FooForm.php I include a fieldset:

public function __construct() {
    // ...
    $this->add(array(
        'type' => 'Collection',
        'name' => 'bar',
        'options' => array(
            'label'=> '',
            'count' => 1,
            'should_create_template' => TRUE,
            'allow_add' => TRUE,
            'use_as_base_fieldset' => TRUE,
            'target_element' => array(
                'type' => 'Lorem\Fieldset\BarFieldset'
            )
        )
    ));
}

In .../Lorem/Fieldset/BarFieldset.php I have:

public function __construct() {
    parent::__construct('bar');
    $this->setHydrator(new ReflectionHydrator())
        ->setObject(new Bar());

    $this->add(array(
       'name'        => 'description',
       'type'        => 'Textarea',
        'attributes' => array(
            'rows'      => 3,
            'cols'      => 40,
        ),
    ));
    $this->add(array(
        'name'       => 'amount',
        'attributes' => array(
            'type'      => 'Text',
            'class'     => 'input-bar-amount',
            'maxlength' => 9,
        ),
    ));
    // ...
}

public function getInputFilterSpecification()
{
    return array(
        'description' => array(
            'required' => TRUE, 
            'filters'   => array(
                array('name' => 'StripTags'),
            ),
            'validators' => array(
                array(
                    'name'    => 'NotEmpty',
                    'break_chain_on_failure' => TRUE,
                    'options' => array(
                        'messages'  => array(
                            'isEmpty' => 'Please enter a description.',
                        ),
                    ),
                ),
            ),
        ),
        'amount' => array(
            'required' => TRUE, 
            'filters'   => array(
                array('name' => 'StripTags'),
                array('name' => 'StringTrim'),
            ),
            'validators' => array(
                array(
                    'name'    => 'NotEmpty',
                    'break_chain_on_failure' => TRUE,
                    'options' => array(
                        'messages'  => array(
                            'isEmpty' => 'Please enter amount.',
                        ),
                    ),
                ),
                array(
                    'name' => 'Float',
                    'break_chain_on_failure' => TRUE,
                    'options' => array(
                        'locale' => 'de',
                        'messages'  => array(
                            'floatInvalid' => 'Invalid input. String, Integer oder Float expected.',
                            'notFloat' => 'Input ist not a floating point number.',
                        ),
                    ),
                ),
                array(
                    'name' => 'Between',
                    'break_chain_on_failure' => TRUE,
                    'options' => array(
                        'min' => -1000000,
                        'max' => 1000000,
                        'messages'  => array(
                            'notBetween'       => "Only values between '%min%' and '%max%' EUR are allowed.",
                            'notBetweenStrict' => "Only values between '%min%' and '%max%' EUR are allowed.",
                        ),
                    ),
                ),
            ),
        ),
        // ...
    );
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等