【发布时间】:2020-05-20 10:42:25
【问题描述】:
我的目标是创建一本书的章节,并且在每一章中,我可以有任意多的章节作为子章节。我有一个实体,它是一本书的一章 对于每一章,我可以添加一个子章(实际上是另一章(但 id parent 不为空))
class Chapter
{
/**
* One champ has One parent champ.
* @ORM\ManyToOne(targetEntity="Chapter", inversedBy="children")
* @ORM\JoinColumn(name="id_parent", referencedColumnName="id")
*/
public $parent;
/**
* One champ has Many champs.
* @ORM\OneToMany(targetEntity="Chapter", mappedBy="parent",cascade={"persist"}))
* @ORM\OrderBy({"ordre" = "ASC"})
*/
public $children;
我想用 symfony 每章的形式添加/删除/修改,所以我有以下表单类型
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('libelleLong', textType::class, ['label'=> 'titre']);
$builder->add('children', CollectionType::class,[
'entry_type' => ChapterType::class,
'entry_options' => ['label' => false,'block_name' => 'childrenList'],
'block_name' => 'childrenList',
'label'=> false,
'allow_add'=>true,
'allow_delete'=> true,
'prototype'=> true,
'by_reference' => false,
]
);
}
但是这条线'prototype'=> true把所有东西都放下了……
[19-May-2020 20:57:08 UTC] PHP 致命错误:允许的内存大小为 134217728 字节用尽(试图分配 32768 字节) 供应商\symfony\symfony\src\Symfony\Component\Debug\Exception\OutOfMemoryException.php 第 1 行
我怎样才能给孩子们提供原型?
【问题讨论】:
标签: php forms symfony collections