Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 来自字段集的ZF2对象_Php_Zend Framework - Fatal编程技术网

Php 来自字段集的ZF2对象

Php 来自字段集的ZF2对象,php,zend-framework,Php,Zend Framework,在ZF2中,我有一个如下所示的字段集: class PhoneRegistrationFieldset extends Fieldset implements InputFilterProviderInterface { public function __construct() { parent::__construct('phoneRegistration'); $this ->setHydrator(new C

在ZF2中,我有一个如下所示的字段集:

class PhoneRegistrationFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function __construct()
    {
        parent::__construct('phoneRegistration');

        $this
            ->setHydrator(new ClassMethods(false))
            ->setObject(new Phone());

        $this->add([
            'type' => 'Zend\Form\Element\Select',
            'name' => 'phoneType',
            'options' => [
                'value_options' => // array of values
            ],
        ]);

        $this->add([
            'name' => 'areaCode',
            'options' => [
                'label' => 'label'
            ],
        ]);
        // other fields
    }
}
表格:

class PhoneRegistrationForm extends Form
{
    public function __construct()
    {
        parent::__construct();

        $this
            ->setAttribute('method', 'post')
            ->setHydrator(new ClassMethods(false))
            ->setInputFilter(new InputFilter());

        $this->add([
            'type' => 'Parties\Form\Fieldsets\PhoneRegistrationFieldset',
        ]);

        $this->add([
            'type' => 'Zend\Form\Element\Button',
            'name' => 'submitPhoneButton',
            'attributes' => [
                'type' => 'submit',
        ]);

    }
}
我在控制器中验证表单。它会得到验证,但在验证过程中,
手机
对象不会被水合。如果在验证后我
dump
对象,则其所有属性都是
NULL
s


如何使附加到字段集的对象水合?

编辑:我的解决方案在ZF3中不起作用

意外地找到了解决方案:我需要在控制器中的窗体上调用
bind()
方法,如下所示:

$this->phoneRegistrationForm->bind(new Phone());
这很有趣,但是您可以将任何对象抛出到
bind()
方法中,并且仍然可以得到字段集的对象


在检查附加到其他字段集的对象的水合作用后,如果调用表单上的
bind()
方法,它们都会水合。希望这对像我这样的ZF2新手有所帮助

编辑:我的解决方案在ZF3中不起作用

意外地找到了解决方案:我需要在控制器中的窗体上调用
bind()
方法,如下所示:

$this->phoneRegistrationForm->bind(new Phone());
这很有趣,但是您可以将任何对象抛出到
bind()
方法中,并且仍然可以得到字段集的对象

在检查附加到其他字段集的对象的水合作用后,如果调用表单上的
bind()
方法,它们都会水合。希望这对像我这样的ZF2新手有所帮助