问题描述
我正在尝试将 Doctrine 2整合到我的Zend 2 中。我希望在我的表格上加入两个实体;即ONeToOne。
I am trying to integrate Doctrine 2 to my Zend 2. I wish to join two entities on my form; i.e ONeToOne.
我按照。
我能够成功地整合原则,并能够水化一个的实体。
I was able to successfully integrate doctrine and was able to Hydrate one of the entities.
当我尝试将第二个实体字段集加入第一个实体时,会出现此问题。我继续收到以下致命错误消息:
The problem occurs when I try to join the second entity fieldset to the first entity. I keep getting the following fatal error message:
我将从fieldets开始,并向您展示如何将ObjectManager传递给两个fieldets。
I will start with the fieldsets and show you how I tried to pass the ObjectManager to both fieldsets.
第一个字段集:AboutYou (这是关系中的所有者);
The first fieldset: AboutYou (This is the owner in the relationship);
我通过控制器页面上的表单传递ObjectManager:
I pass the ObjectManager through the form on the controller page:
$form = new CreateAboutYouForm($this->getEntityManager());
下面的代码的第一部分单独工作。即如果我不将workeraddressfieldset放在代码中。
The first part of the below code works alone. i.e if i dont place the workeraddressfieldset into the code.
class AboutYouFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct(ObjectManager $objectManager)
{
parent::__construct('AboutYou');
$this->setHydrator(new DoctrineHydrator($objectManager, 'Workers\Entity\AboutYou'))
->setObject(new AboutYou());
$this->add(array(
'name' => 'firstName',
'type' => 'Text',
'options' => array(
'label' => 'First Name',
),
));
$addressFieldset = new WorkerAddressFieldset($objectManager);
$this->add(array(
'type' => 'Workers\Form\Fieldset\workerAddressFieldset',
'name' => 'WorkerAddress',
'options' => array(
'label' => $addressFieldset
)
));
}
您会注意到,我创建了一个 workerAddressFieldset对象,并尝试将ObjectManager传递到类中。但它似乎没有得到价值观。我不清楚为什么。
You will notice above that I created a workerAddressFieldset object and attempted to pass the ObjectManager into the class that way. But it does not seem to receive the values. I am not clear why.
第二个字段集(workersAddress):
The second fieldset (the workersAddress):
class WorkerAddressFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct(ObjectManager $objectManager)
{
parent::__construct('WorkerAddress');
$this->setHydrator(new DoctrineHydrator($objectManager, 'Workers\Entity\WorkerAddress'))
->setObject(new WorkerAddress());
}
我真的很感激一些建议或工作样本如何其他人已经能够一起加入这些野战队。
I would really appreciate some advice or a working sample of how others have been able to join the fieldsets together.
推荐答案
这是因为您尝试从String中添加Fieldset。鉴于您的 AddressFieldset
有一个 __结构(ObjectManager $ om)
,但是您首先需要实例化FieldSet,然后将其添加到您的表单。喜欢:
That's because you try to add the Fieldset from String. Given the fact that your AddressFieldset
has a __construct(ObjectManager $om)
however you first need to instantiate the Fieldset and then add it to your form. Like:
class AboutYouFieldset extends Fieldset
{
public function __construct(ObjectManager $objectManager)
{
parent::__construct('about-you');
$this->add(); // your first element
$fieldset = new WorkerAddressFieldset($objectManager);
$this->add($fieldset);
}
}
这篇关于zend2 doctrine 2 form intgergration OneToOne的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!