4
由于围绕此主题的文档有点简单,所以我陷入了一个死胡同。
我有两个模型:Job和JobAttribute。 一个工作有很多的JobAttributes和JobAttribute有一个工作:
class Job {
/**
* @ORM\OneToMany(targetEntity="JobAttribute", mappedBy="job_attributes")
*
* @var ArrayCollection
*/
private $attributes;
}
class JobAttribute {
/**
* @ORM\Column(name="type", type="string", length=50)
*
* @var string
*/
private $type;
/**
* @ORM\ManyToOne(targetEntity="Job", inversedBy="jobs")
*/
private $job;
现在,我有以下FormClass:
class JobType extends AbstractType {
public function buildForm(FormBuilder $f, array $options) {
$f->add('name', 'text');
$f->add('attributes', 'collection', array('type' => new JobAttributeType()));
}
public function getName() {
return 'job';
}
}
class JobAttributeType extends AbstractType {
public function buildForm(FormBuilder $f, array $options) {
$attribute = $options['data'];
$f->add('value', $attribute->getType());
}
public function getDefaultOptions(array $options) {
return array('data_class' => 'JWF\WorkflowBundle\Entity\JobAttribute');
}
public function getName() {
return 'job_attribute';
}
}
是的,的确,JobAttribute的type属性包含窗体字段类型,例如。文本。
因此,当我在我的Controller的JobType中调用FormBuilder时,$ Job ['data']在JobType中正确填充Job-Object。 但嵌套的JobAttributeType的$ options ['data']不指向JobAttribute对象。它是NULL。
有什么问题?该协会失去了什么?为什么嵌套表单中的$ options ['data'] = NULL? 是否有一种解决方法,以获得嵌套形式的动态字段类型(超出Doctrine)?
在此先感谢!
嗨伯恩哈德。什么是需要表单数据的'DataTransformer'?在'PRE_SET_DATA'事件中,我无法做任何事情,如果'options ['data']'在构建过程中没有值,我该如何连接变压器?谢谢。 – DonCallisto 2016-09-02 09:13:56