duanmao1975 2015-06-11 14:08
浏览 41

ZF2形式与fieldset和doctrine不起作用

I have a problem with a form, fieldset and doctrine. This is my edit form. In this form I add the User Fieldset and add another field "password" (that I use only in this form).

EditUserForm:

class EditUserForm extends Form implements InputFilterProviderInterface
{
    public function __construct($name = null, $options = [])
    {
        parent::__construct($name, $options);

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

        $this->add([
            'name'    => 'user',
            'type'    => 'Application\Form\UserFieldset',
            'options' => [
                'use_as_base_fieldset' => true
            ]
        ]);

        $this->add([
            'name'       => 'password',
            'type'       => 'Zend\Form\Element\Password',
            'attributes' => [
                'id'    => 'password'
            ]
        ]);
    }

    public function getInputFilterSpecification()
    {
        return [
            'password' => [
                'required' => true
            ],
        ];
    }

}

UserFieldset:

class UserFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function __construct($name = null, $options = [])
    {
        parent::__construct($name, $options);

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

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

        $this->add([
            'name'       => 'surname',
            'type'       => 'Zend\Form\Element\Text',
            'attributes' => [
                'id'    => 'surname'
            ]
        ]);
    }

    public function getInputFilterSpecification()
    {
        return [
            'name' => [
                'required' => true
            ],
            'surname' => [
                'required' => true
            ],
        ];
    }
}

Why if I try to var_dump(form->getData()) does the entity does not have the password field?

object(Application\Entity\User)[114]
  private 'name' => string 'john' (length=4)
  private 'surname' => string 'smith' (length=5)
  private 'password' => null

thanks.

  • 写回答

1条回答 默认 最新

  • douhan6738 2015-06-11 14:44
    关注

    The password needs to be part of the UserFieldset as you're setting the UserFieldset as base-fieldset. If you choose a base-fieldset, only this fieldset will be hydrated recursively.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向