如何在ZF2中扩展一个字段集以使用Doctrine的Class Table继承映射策略 [英] How to Extend a Fieldset in ZF2 to work with Doctrine’s Class Table Inheritance mapping strategy

查看:127
本文介绍了如何在ZF2中扩展一个字段集以使用Doctrine的Class Table继承映射策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Doctrine的Class Table Inheritance映射策略来开发一个项目,该策略涉及将父表与多个子表之一相加,这取决于父表中的discriminator列中的值。我有一个工作原型,其中唯一的集合字段集包含来自父实体的常见元素的所有代码的重复副本。为了确保一致性并避免过多的代码,我想更改这些字段集,以便我有一个与父实体相关的字段集,而所有其他字段只是父级的扩展(详细说明包括在如何在ZF2中扩展字段集)。我分离了这些字段时遇到问题,然后尝试让他们相互合作。



问题的第一个答案是如何在ZF2中扩展字段集提供了一个明确的解释,说明如何在ZF2中单个字段集可以扩展另一个字段集。然而,答案使用 init()来组合字段集,对于Doctrine策略,我们需要使用 __ construct 。我第一次开发fieldets的过程是建立在 DoctrineModule / docs ,这使我们这样做:

  class FieldsetParent extends Zend\Form\ Fieldset 
{
public function __construct(ObjectManager $ objectManager){

parent :: __ construct('parent-fieldset');

$ this-> setHydrator(new DoctrineHydrator($ objectManager,'MyModule\Entity\Parent'))
- > setObject(new Parent());

$ this-> add(array('name'=>'fieldA'));
$ this-> add(array('name'=>'fieldB'));
$ this-> add(array('name'=>'fieldC'));
}
}

而这个:

  class FieldsetFoo extends FieldsetParent 
{
public function __construct(ObjectManager $ objectManager){

parent :: __ construct ( '富-字段集');

$ this-> setHydrator(new DoctrineHydrator($ objectManager,'MyModule\Entity\Foo'))
- > setObject(new Foo());

$ this-> add(array('name'=>'fieldD'));
$ this-> add(array('name'=>'fieldE'));
$ this-> add(array('name'=>'fieldF'));
$ this-> add(array('name'=>'fieldG'));
}
}

这不行,因为它尝试添加字段集,出现错误消息:

 可追加的致命错误:参数1传递到MyModuule\Form\ParentFieldset: :__ construct()
必须实现接口Doctrine\Common\Persistence\ObjectManager,string given ...

zend2 doctrine 2 form intgergration OneToOne 的第一个答案解释了如何从字符串中添加字段集在OneToOne策略的情况下避免。但是,我正在使用一个不同的ORM策略,我在解决同样的问题时遇到困难。



编辑 / h1>

根据要求,这里有一些更详细的信息:

  class FooController extends AbstractActionController 
{
/ **
* @var Doctrine\ORM\EntityManager
* /
protected $ em;

public function setEntityManager(EntityManager $ em)
{
$ this-> em = $ em;
return $ this;
}

public function getEntityManager()
{
if(null === $ this-> em){
$ this-> em = $ this-> getServiceLocator() - > get('Doctrine\ORM\EntityManager');
}
return $ this-> em;
}

// ... //

public function editAction()
{
$ fooID =(int)$ this - > getEvent() - > getRouteMatch() - > getParam( 'fooID');
if(!$ fooID){
return $ this-> redirect() - > toRoute('foo',array('action'=>'add'));
}

$ foo = $ this-> getEntityManager() - > find('MyModule\Entity\Foo',$ fooID);

//从ServiceManager获取您的ObjectManager
$ objectManager = $ this-> getServiceLocator() - > get('Doctrine\ORM\EntityManager');

//创建表单并注入ObjectManager
$ form = new EditFooForm($ objectManager);
$ form-> setBindOnValidate(false);
$ form-> bind($ foo);
$ form-> get('submit') - > setAttribute('label','Update');

$ request = $ this-> getRequest();
if($ request-> isPost()){
$ form-> setData($ request-> getPost());
if($ form-> isValid()){
$ form-> bindValues();
$ this-> getEntityManager() - > flush();

return $ this-> redirect() - > toRoute('foo');
}
}

返回数组(
'foo'=> $ foo,
'form'=&$ $ form,
);
}

}

  class EditFooForm extends Form 
{
public function __construct(ObjectManager $ objectManager)
{
parent: :__构建体( 'edit_foo_form');

$ this-> setHydrator(new DoctrineHydrator($ objectManager,'MyModule\Entity\Foo'));

$ fooFieldset = new FooFieldset($ objectManager);
$ fooFieldset-> setUseAsBaseFieldset(true);
$ this-> add($ fooFieldset);

//提交元素
}
}

此字段集工作:

  class FooFieldset extends Fieldset implements InputFilterProviderInterface 
{
public function __construct(ObjectManager $ objectManager)
{
parent :: __ construct('foo-fieldset');

$ this-> setHydrator(new DoctrineHydrator($ objectManager,'MyModule\Entity\Foo'))
- > setObject(new Foo());

$ this-> add(array('name'=>'fieldA'));
$ this-> add(array('name'=>'fieldB'));
$ this-> add(array('name'=>'fieldC'));
$ this-> add(array('name'=>'fieldD'));
$ this-> add(array('name'=>'fieldE'));
$ this-> add(array('name'=>'fieldF'));
$ this-> add(array('name'=>'fieldG'));

}

public function getInputFilterSpecification()
{
return array('fieldA'=> array('required'=> false) ,);
return array('fieldB'=> array('required'=> false),);
return array('fieldC'=> array('required'=> false),);
return array('fieldD'=> array('required'=> false),);
return array('fieldE'=> array('required'=> false),);
return array('fieldF'=> array('required'=> false),);
return array('fieldG'=> array('required'=> false),);

}

}

一个错误消息:

  class FoobarFieldset extends Fieldset implements InputFilterProviderInterface 
{
public function __construct(ObjectManager $ objectManager )
{
parent :: __ construct('foobar-fieldset');

$ this-> setHydrator(new DoctrineHydrator($ objectManager,'MyModule\Entity\Foobar'))
- > setObject(new Foobar());

$ this-> add(array('name'=>'fieldA'));
$ this-> add(array('name'=>'fieldB'));
$ this-> add(array('name'=>'fieldC'));

}

public function getInputFilterSpecification()
{
return array('fieldA'=> array('required'=> false) ,);
return array('fieldB'=> array('required'=> false),);
return array('fieldC'=> array('required'=> false),);

}

}

p>

 使用MyModule\Form\FoobarFieldset; 

class FooFieldset extends FoobarFieldset implements InputFilterProviderInterface
{
public function __construct(ObjectManager $ objectManager)
{
parent :: __ construct('foo-fieldset' );

$ this-> setHydrator(new DoctrineHydrator($ objectManager,'MyModule\Entity\Foo'))
- > setObject(new Foo());

$ this-> add(array('name'=>'fieldD'));
$ this-> add(array('name'=>'fieldE'));
$ this-> add(array('name'=>'fieldF'));
$ this-> add(array('name'=>'fieldG'));

}

public function getInputFilterSpecification()
{
return array('fieldD'=> array('required'=> false) ,);
return array('fieldE'=> array('required'=> false),);
return array('fieldF'=> array('required'=> false),);
return array('fieldG'=> array('required'=> false),);

}

}

产生的错误消息是:

 可追加的致命错误:参数1传递到MyModule\Form\FoobarFieldset :: __ construct()
必须实现接口Doctrine\Common\Persistence\ObjectManager,字符串给定,在C:\xampp\htdocs\GetOut\module\MyModule\src\MyModule\Form中调用
第17行
上的\FooFieldset.php,并在C:\xampp\htdocs\GetOut\module\MyModule\src\MyModule\Form\FoobarFieldset.php
中定义在线14

我尝试避免通过进行这些更改从字符串中添加字段集: p>

 使用MyModule\Form\FoobarFieldset; 

class FooFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct(ObjectManager $ objectManager)
{
parent :: __ construct('foo-fieldset' );

$ this-> setHydrator(new DoctrineHydrator($ objectManager,'MyModule\Entity\Foo'))
- > setObject(new Foo());

$ this-> add(array('name'=>'fieldD'));
$ this-> add(array('name'=>'fieldE'));
$ this-> add(array('name'=>'fieldF'));
$ this-> add(array('name'=>'fieldG'));

$ fieldset = new FoobarFieldset($ objectManager);
$ this-> add($ fieldset);

}

但这给了一个 Zend \\ Form\Exception\InvalidElementException 带有消息,没有元素以[fieldA]的名称在表单中找到,表示该文件集是没有添加。



AN ALNANATIVE



当所有的说完,完成后,我真的想do将所有常见语句保存在一个地方,并将它们绘制到需要包含它们的各种唯一的fieldets中。我可以通过使用 include 语句来解决这个问题,如下所示:

  // FoobarFieldset_fields.php 

$ this-> add(array('name'=>'fieldA'));
$ this-> add(array('name'=>'fieldB'));
$ this-> add(array('name'=>'fieldC'));

  // FoobarFieldset_filters.php 

return array('fieldA'=> array('required'=> false),);
return array('fieldB'=> array('required'=> false),);
return array('fieldC'=> array('required'=> false),);

  class FooFieldset extends Fieldset implements InputFilterProviderInterface 
{
public function __construct(ObjectManager $ objectManager)
{
parent :: __ construct('foo-fieldset');

$ this-> setHydrator(new DoctrineHydrator($ objectManager,'MyModule\Entity\Foo'))
- > setObject(new Foo());

包含FoobarFieldset_fields.php;
$ this-> add(array('name'=>'fieldD'));
$ this-> add(array('name'=>'fieldE'));
$ this-> add(array('name'=>'fieldF'));
$ this-> add(array('name'=>'fieldG'));

}

public function getInputFilterSpecification()
{
include'FoobarFieldset_filters.php';
return array('fieldD'=> array('required'=> false),);
return array('fieldE'=> array('required'=> false),);
return array('fieldF'=> array('required'=> false),);
return array('fieldG'=> array('required'=> false),);

}

}


解决方案

您所涉及的问题与字段集的 __结构



父 / p>

  class FoobarFieldset extends Fieldset {
public function __construct(ObjectManager $ objectManager){}

然而,在'child'中,您调用父代 __构造传递一个字符串它应该是$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ face face face face face face face face face face face face face face face face face face face face face
{
public function __construct(ObjectManager $ objectManager)
{
parent :: __ construct('foo-fieldset'); //这应该是$ objectManager,而不是字符串

还有一些其他的东西可以改善你的代码。



目前您正在使用新的关键字创建表单。

  $ form = new EditFooForm($ objectManager); 

这很好(它会工作),但是你应该真正通过服务管理器加载它你要附加一个工厂。

  $ form = $ this-> getServiceLocator() - > get('MyModule \Form\EditFoForm'); 

然后,您将有一个工厂注册来创建新的表单和字段集(将所有的构造代码保存在一个地方)



Module.php

  public function getFormElementConfig()
{
return array(
'factoryories'=> array(
'MyModule\Form\EditFooForm'=> function ();
//注入表单填充
$ sm = $ fem-> getServiceLocator();
$ om = $ sm-> get('object_manager');

返回新的EditFooForm($ om);
},
'MyModule\Form\EditFooFieldset'=> function($ fem){
//注入字段集
$ sm = $ fem-> getServiceLocator();
$ om = $ sm-> get('object_manager');

$ fieldset = new EditFooFieldset om);

$ hydrator = $ sm-> get('HydratorManager');
//你也可以通过工厂
//创建水化器,并将其注入到表单外面,这意味着您不需要这样做
//在
$ hydrator = $ hydrator-> ;获得( 'MyFooHydrator');
$ fieldset-> setHydrator($ hydrator);

return $ fieldset;
},

),
);
}

最后;允许 Zend\Form\Factory 创建字段集,方法是通过 $ this-> add()(而不是使用 new 在窗体内创建字段集)

  FooFieldset类扩展FieldSet实现InputFilterProviderInterface 
{
public function init()
{
// .....
//允许字段集通过FormElementManager
//并使用新工厂
$ this-> add(array(
'name'=>'foo_fieldset',
'type'=> 'MyModule\Form\EditFooFieldset',
));

// ....

}
}

注意在最后一个例子中,表单元素在 init()中添加,这是因为 FormElementManager 将调用 init()。这是一个重要的关注点,因为它将允许您通过 __构造注入(创建表单时)提供依赖关系,然后单独添加表单元素



这是解释文件


[...]你不能直接实例化你的表单类,而是通过 Zend\Form\FormElementManager 获得一个实例:


还有:


如果您正在创建表单类通过扩展 Zend\Form\Form ,您不能在 __构造中添加自定义元素 -or(as我们在前一个例子中已经完成了我们使用自定义元素的FQCN),而是在 init()中thod:



I’m developing a project using Doctrine’s Class Table Inheritance mapping strategy which involves joining a parent table with one of a number of child tables depending on the value in a discriminator column in the parent table. I’ve got a working prototype in which the unique conglomerate fieldsets each contain duplicate copies of all of the code for the common elements from the parent entity. In order to ensure consistency and avoid excess code I want to change the fieldsets so that I have a single fieldset that’s related to the parent entity and all of the other fieldsets are simply extensions of the parent (a detailed explanation is included at How to Extend a Fieldset in ZF2). I run into problems when I separate the fieldsets and then try to get them to work with each other.

The first answer to the question How to Extend a Fieldset in ZF2 provides a clear explaination of how a single fieldset can extend another in ZF2. However, the answer uses init() to put together the fieldsets, and for the Doctrine strategy we need to use __construct. My first pass in developing the fieldsets was to build in the some of the code prescribed in the DoctrineModule/docs, which brings us to this:

class FieldsetParent extends Zend\Form\Fieldset
{
   public function __construct(ObjectManager $objectManager) {

        parent::__construct('parent-fieldset');

        $this->setHydrator(new DoctrineHydrator($objectManager, 'MyModule\Entity\Parent'))
             ->setObject(new Parent());

        $this->add(array('name' => 'fieldA'));
        $this->add(array('name' => 'fieldB'));
        $this->add(array('name' => 'fieldC'));
   }
}

and this:

class FieldsetFoo extends FieldsetParent
{
   public function __construct(ObjectManager $objectManager) {

        parent::__construct('foo-fieldset');

        $this->setHydrator(new DoctrineHydrator($objectManager, 'MyModule\Entity\Foo'))
             ->setObject(new Foo());

        $this->add(array('name' => 'fieldD'));
        $this->add(array('name' => 'fieldE'));
        $this->add(array('name' => 'fieldF'));
        $this->add(array('name' => 'fieldG'));
   }
}

This doesn’t work because it attempts to add a fieldset from a string, giving the error message:

Catchable fatal error: Argument 1 passed to MyModuule\Form\ParentFieldset::__construct() 
must implement interface Doctrine\Common\Persistence\ObjectManager, string given ...

The first answer to the question zend2 doctrine 2 form intgergration OneToOne explains how adding a fieldset from a string can be avoided in the case of a OneToOne strategy. However, I'm working with a different ORM strategy and I’m having difficulties working out how to solve the same problem.

EDIT

As requested, here is some more detailed information:

class FooController extends AbstractActionController
{
    /**
     * @var Doctrine\ORM\EntityManager
     */
    protected $em;

    public function setEntityManager(EntityManager $em)
    {
        $this->em = $em;
        return $this;
    }

    public function getEntityManager()
    {
        if (null === $this->em) {
            $this->em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
        }
        return $this->em;
    }

    // ... //

    public function editAction()
    {
        $fooID = (int)$this->getEvent()->getRouteMatch()->getParam('fooID');
        if (!$fooID) {
            return $this->redirect()->toRoute('foo', array('action'=>'add'));
        }

        $foo = $this->getEntityManager()->find('MyModule\Entity\Foo', $fooID);

        // Get your ObjectManager from the ServiceManager
        $objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');

        // Create the form and inject the ObjectManager
        $form = new EditFooForm($objectManager);
        $form->setBindOnValidate(false);
        $form->bind($foo);
        $form->get('submit')->setAttribute('label', 'Update');

        $request = $this->getRequest();
        if ($request->isPost()) {
            $form->setData($request->getPost());
            if ($form->isValid()) {
                $form->bindValues();
                $this->getEntityManager()->flush();

                return $this->redirect()->toRoute('foo');
            }
        }

        return array(
            'foo' => $foo,
            'form' => $form,
        );
    }

}

and

class EditFooForm extends Form
{
    public function __construct(ObjectManager $objectManager)
    {
        parent::__construct('edit_foo_form');

        $this->setHydrator(new DoctrineHydrator($objectManager, 'MyModule\Entity\Foo'));

        $fooFieldset = new FooFieldset($objectManager);
        $fooFieldset->setUseAsBaseFieldset(true);
        $this->add($fooFieldset);

        // submit elements
    }
}

This fieldset works:

class FooFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function __construct(ObjectManager $objectManager)
    {
        parent::__construct('foo-fieldset');

        $this->setHydrator(new DoctrineHydrator($objectManager, 'MyModule\Entity\Foo'))
             ->setObject(new Foo());

        $this->add(array('name' => 'fieldA'));
        $this->add(array('name' => 'fieldB'));
        $this->add(array('name' => 'fieldC'));
        $this->add(array('name' => 'fieldD'));
        $this->add(array('name' => 'fieldE'));
        $this->add(array('name' => 'fieldF'));
        $this->add(array('name' => 'fieldG'));

    }

    public function getInputFilterSpecification()
    {
        return array('fieldA' => array('required' => false),);
        return array('fieldB' => array('required' => false),);
        return array('fieldC' => array('required' => false),);
        return array('fieldD' => array('required' => false),);
        return array('fieldE' => array('required' => false),);
        return array('fieldF' => array('required' => false),);
        return array('fieldG' => array('required' => false),);

    }

}

These fieldsets give an error message:

class FoobarFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function __construct(ObjectManager $objectManager)
    {
        parent::__construct('foobar-fieldset');

        $this->setHydrator(new DoctrineHydrator($objectManager, 'MyModule\Entity\Foobar'))
             ->setObject(new Foobar());

        $this->add(array('name' => 'fieldA'));
        $this->add(array('name' => 'fieldB'));
        $this->add(array('name' => 'fieldC'));

    }

    public function getInputFilterSpecification()
    {
        return array('fieldA' => array('required' => false),);
        return array('fieldB' => array('required' => false),);
        return array('fieldC' => array('required' => false),);

    }

}

and

use MyModule\Form\FoobarFieldset;

class FooFieldset extends FoobarFieldset implements InputFilterProviderInterface
{
    public function __construct(ObjectManager $objectManager)
    {
        parent::__construct('foo-fieldset');

        $this->setHydrator(new DoctrineHydrator($objectManager, 'MyModule\Entity\Foo'))
             ->setObject(new Foo());

        $this->add(array('name' => 'fieldD'));
        $this->add(array('name' => 'fieldE'));
        $this->add(array('name' => 'fieldF'));
        $this->add(array('name' => 'fieldG'));

    }

    public function getInputFilterSpecification()
    {
        return array('fieldD' => array('required' => false),);
        return array('fieldE' => array('required' => false),);
        return array('fieldF' => array('required' => false),);
        return array('fieldG' => array('required' => false),);

    }

}

The resulting error message is:

Catchable fatal error: Argument 1 passed to MyModule\Form\FoobarFieldset::__construct() 
must implement interface Doctrine\Common\Persistence\ObjectManager, string given, called
in C:\xampp\htdocs\GetOut\module\MyModule\src\MyModule\Form\FooFieldset.php on line 17 
and defined in C:\xampp\htdocs\GetOut\module\MyModule\src\MyModule\Form\FoobarFieldset.php
on line 14

I have tried to avoid adding a fieldset from a string by making these changes:

use MyModule\Form\FoobarFieldset;

class FooFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function __construct(ObjectManager $objectManager)
    {
        parent::__construct('foo-fieldset');

        $this->setHydrator(new DoctrineHydrator($objectManager, 'MyModule\Entity\Foo'))
             ->setObject(new Foo());

        $this->add(array('name' => 'fieldD'));
        $this->add(array('name' => 'fieldE'));
        $this->add(array('name' => 'fieldF'));
        $this->add(array('name' => 'fieldG'));

        $fieldset = new FoobarFieldset($objectManager);
        $this->add($fieldset);

    }

but this gives a Zend\Form\Exception\InvalidElementException with the message, No element by the name of [fieldA] found in form, indicating that the filedset is not getting added.

AN ALTERNATIVE

When it’s all said and done, all I’m really trying to do is keep all of the common statements in one place and draw them into the various unique fieldsets that need to include them. I can solve this without ZF2 by using include statements as shown below:

// FoobarFieldset_fields.php

$this->add(array('name' => 'fieldA'));
$this->add(array('name' => 'fieldB'));
$this->add(array('name' => 'fieldC'));

and

// FoobarFieldset_filters.php

return array('fieldA' => array('required' => false),);
return array('fieldB' => array('required' => false),);
return array('fieldC' => array('required' => false),);

and

class FooFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function __construct(ObjectManager $objectManager)
    {
        parent::__construct('foo-fieldset');

        $this->setHydrator(new DoctrineHydrator($objectManager, 'MyModule\Entity\Foo'))
             ->setObject(new Foo());

        include 'FoobarFieldset_fields.php';
        $this->add(array('name' => 'fieldD'));
        $this->add(array('name' => 'fieldE'));
        $this->add(array('name' => 'fieldF'));
        $this->add(array('name' => 'fieldG'));

    }

    public function getInputFilterSpecification()
    {
        include 'FoobarFieldset_filters.php';
        return array('fieldD' => array('required' => false),);
        return array('fieldE' => array('required' => false),);
        return array('fieldF' => array('required' => false),);
        return array('fieldG' => array('required' => false),);

    }

}

解决方案

The issue you are having relates to the fieldset's __construct

The 'parent'

class FoobarFieldset extends Fieldset {
    public function __construct(ObjectManager $objectManager) {}

In the 'child' however you are calling the parent __construct passing a string (which should be the $objectManager)

class FooFieldset extends FoobarFieldset implements InputFilterProviderInterface
{
  public function __construct(ObjectManager $objectManager)
  {
     parent::__construct('foo-fieldset'); // This should be $objectManager, not string

There are some additional things that could improve your code.

Currently you are creating the form using the new keyword.

$form = new EditFooForm($objectManager);

This is fine (it will work) however you should really be loading it via the service manager to allow you to attach a factory to it.

$form = $this->getServiceLocator()->get('MyModule\Form\EditFoForm');

Then you would have a factory registered to create the new form and fieldset (keeping all the construction code in one place)

Module.php

public function getFormElementConfig()
{
  return array(
    'factories' => array(
       'MyModule\Form\EditFooForm' => function($fem) {
          // inject form stuff
          $sm = $fem->getServiceLocator();
          $om = $sm->get('object_manager');

          return new EditFooForm($om);
       },
       'MyModule\Form\EditFooFieldset' => function($fem) {
          // inject fieldset stuff
          $sm = $fem->getServiceLocator();
          $om = $sm->get('object_manager');

          $fieldset = new EditFooFieldset($om);

          $hydrator = $sm->get('HydratorManager');
          // you can also create the hydrator via a factory
          // and inject it outside the form, meaning you don't need to do so
          // within the form
          $hydrator = $hydrator->get('MyFooHydrator'); 
          $fieldset->setHydrator($hydrator);

          return $fieldset;
       },

    ),
  );
}

Lastly; allow the Zend\Form\Factory to create the fieldset by adding it via $this->add() (rather than creating the fieldset within the form using new)

    class FooFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function init()
    {
        //.....
        // Allow the fieldset to be loaded via the FormElementManager 
        // and use the new factory
        $this->add(array(
            'name' => 'foo_fieldset',
            'type' => 'MyModule\Form\EditFooFieldset',
        ));

        // ....

    }
}

Notice in the last example the form elements are added in init() this is because the FormElementManager will call init() when you request it from the service manager. This is an important separation of concerns as it will allow you to provide the dependencies via __construct injection (when the form is created) and then separately add the form elements after all the forms properties have been set.

This is explained within the documentation:

[...] you must not directly instantiate your form class, but rather get an instance of it through the Zend\Form\FormElementManager:

and also:

If you are creating your form class by extending Zend\Form\Form, you must not add the custom element in the __construct -or (as we have done in the previous example where we used the custom element’s FQCN), but rather in the init() method:

这篇关于如何在ZF2中扩展一个字段集以使用Doctrine的Class Table继承映射策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆