Php 奏鸣曲管理“;奏鸣曲“U型”系列;尝试删除实体
我有两个实体和两个管理类(StripePage和Stripe)。表单看起来不错,它有我的字段和按钮来添加新的子表单。单击“添加新”按钮时,将呈现具有来自管理类的表单的新子表单,但如果再次单击此按钮或尝试保存实体,则会出现错误: 可捕获致命错误:参数1传递给 Fred\CoreBundle\Entity\StripePage::removeStripe()必须是实例 Fred\CoreBundle\Entity\Stripe的值,中给出了null C:\Users\lubimov\OpenServer\domains\tappic.dev\src\Fred\CoreBundle\Entity\StripePage.php 所以symfony尝试删除实体而不是添加它 StripePageAdmin类:Php 奏鸣曲管理“;奏鸣曲“U型”系列;尝试删除实体,php,symfony,sonata-admin,Php,Symfony,Sonata Admin,我有两个实体和两个管理类(StripePage和Stripe)。表单看起来不错,它有我的字段和按钮来添加新的子表单。单击“添加新”按钮时,将呈现具有来自管理类的表单的新子表单,但如果再次单击此按钮或尝试保存实体,则会出现错误: 可捕获致命错误:参数1传递给 Fred\CoreBundle\Entity\StripePage::removeStripe()必须是实例 Fred\CoreBundle\Entity\Stripe的值,中给出了null C:\Users\lubimov\OpenServ
class StripePageAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id', null, array('label' => 'id'))
->add('name', null, array('label' => 'Page name'));
}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text', array('label' => 'Page name'))
->add('stripes', 'sonata_type_collection',
array('label' => 'Stripes', 'required' => false, 'by_reference' => false),
array('edit' => 'inline', 'inline' => 'table', 'sortable' => 'pos')
)
->end();
}
}
class StripeAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('picture', null, array('sortable' => true))
->add('text', null, array('sortable' => true))
->add('deep_link', null, array('sortable' => true));
}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('file', 'file', array('label' => 'Picture'))
->add('text', null, array('label' => 'Text'))
->add('deep_link', 'choice', array(
'choices' => array('test1' => 'Test1', 'test' => 'Test2'),
'label' => 'Deep Link',
))
->end();
}
}
StripeAdmin类:
class StripePageAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id', null, array('label' => 'id'))
->add('name', null, array('label' => 'Page name'));
}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text', array('label' => 'Page name'))
->add('stripes', 'sonata_type_collection',
array('label' => 'Stripes', 'required' => false, 'by_reference' => false),
array('edit' => 'inline', 'inline' => 'table', 'sortable' => 'pos')
)
->end();
}
}
class StripeAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('picture', null, array('sortable' => true))
->add('text', null, array('sortable' => true))
->add('deep_link', null, array('sortable' => true));
}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('file', 'file', array('label' => 'Picture'))
->add('text', null, array('label' => 'Text'))
->add('deep_link', 'choice', array(
'choices' => array('test1' => 'Test1', 'test' => 'Test2'),
'label' => 'Deep Link',
))
->end();
}
}
有什么问题?admin类中的条带表单必须以其他方式配置?好吧,我现在使用的解决方案是在“sonata类型集合”设置中设置
'by\u reference'=>true
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text', array('label' => 'Page name'))
->add('stripes', 'sonata_type_collection',
array('label' => 'Stripes', 'required' => false, 'by_reference' => true),
array('edit' => 'inline', 'inline' => 'table', 'sortable' => 'pos')
)
->end();
}
在此之后,需要在实体中声明setStripes()
方法
public function setStripes(\Doctrine\Common\Collections\ArrayCollection $stripes) {
$this->stripes = $stripes;
}
如果有人发现如何使用addStripe()
类型的方法解决此问题,请在此处共享