注意:未定义的索引:在Sonata管理中添加多选时的父级



我正在做与此类似的aswer:

https://stackoverflow.com/a/32264748/6737670

->add('dependsOn', 'entity',  array(
'class' => ProductOption::class,
'attr' => array('class' => "form-control",  'multiple' => true),
'required' => false,
'multiple'=> true,
)
);

但是加载表单时出现错误

注意:未定义的索引:父级

[1] SymfonyComponentDebugExceptionContextErrorException: Notice: Undefined index: parent
at n/a
in /home/darius/PhpstormProjects/vop/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php line 1768
at SymfonyComponentDebugErrorHandler->handleError('8', 'Undefined index: parent', '/home/darius/PhpstormProjects/vop/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php', '1768', array('assoc' => array('fieldName' => 'dependsOn', 'mappedBy' => 'parent', 'targetEntity' => 'VopProductBundleEntityProductOption', 'cascade' => array(), 'orphanRemoval' => false, 'fetch' => '2', 'type' => '4', 'inversedBy' => null, 'isOwningSide' => false, 'sourceEntity' => 'VopProductBundleEntityProductOption', 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false), 'sourceEntity' => object(ProductOption), 'offset' => null, 'limit' => null, 'criteria' => array(), 'parameters' => array()))
in /home/darius/PhpstormProjects/vop/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php line 1768
at DoctrineORMPersistersEntityBasicEntityPersister->getOneToManyStatement(array('fieldName' => 'dependsOn', 'mappedBy' => 'parent', 'targetEntity' => 'VopProductBundleEntityProductOption', 'cascade' => array(), 'orphanRemoval' => false, 'fetch' => '2', 'type' => '4', 'inversedBy' => null, 'isOwningSide' => false, 'sourceEntity' => 'VopProductBundleEntityProductOption', 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false), object(ProductOption))
in /home/darius/PhpstormProjects/vop/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php line 1747
at DoctrineORMPersistersEntityBasicEntityPersister->loadOneToManyCollection(array('fieldName' => 'dependsOn', 'mappedBy' => 'parent', 'targetEntity' => 'VopProductBundleEntityProductOption', 'cascade' => array(), 'orphanRemoval' => false, 'fetch' => '2', 'type' => '4', 'inversedBy' => null, 'isOwningSide' => false, 'sourceEntity' => 'VopProductBundleEntityProductOption', 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false), object(ProductOption), object(PersistentCollection))
in /home/darius/PhpstormProjects/vop/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2826
at DoctrineORMUnitOfWork->loadCollection(object(PersistentCollection))
in /home/darius/PhpstormProjects/vop/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php line 697
at DoctrineORMPersistentCollection->doInitialize()
in /home/darius/PhpstormProjects/vop/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php line 214
at DoctrineORMPersistentCollection->initialize()
in /home/darius/PhpstormProjects/vop/vendor/doctrine/collections/lib/Doctrine/Common/Collections/AbstractLazyCollection.php line 157
at DoctrineCommonCollectionsAbstractLazyCollection->toArray()
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php line 49
at SymfonyBridgeDoctrineFormDataTransformerCollectionToArrayTransformer->transform(object(PersistentCollection))
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 1146
at SymfonyComponentFormForm->normToView(object(PersistentCollection))
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 353
at SymfonyComponentFormForm->setData(object(PersistentCollection))
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57
at SymfonyComponentFormExtensionCoreDataMapperPropertyPathMapper->mapDataToForms(object(ProductOption), object(RecursiveIteratorIterator))
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 386
at SymfonyComponentFormForm->setData(object(ProductOption))
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57
at SymfonyComponentFormExtensionCoreDataMapperPropertyPathMapper->mapDataToForms(object(PersistentCollection), object(RecursiveIteratorIterator))
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 386
at SymfonyComponentFormForm->setData(object(PersistentCollection))
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57
at SymfonyComponentFormExtensionCoreDataMapperPropertyPathMapper->mapDataToForms(object(ProductOptionGroup), object(RecursiveIteratorIterator))
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 386
at SymfonyComponentFormForm->setData(object(ProductOptionGroup))
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 478
at SymfonyComponentFormForm->initialize()
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 226
at SymfonyComponentFormFormBuilder->getForm()
in /home/darius/PhpstormProjects/vop/src/Vop/ProductBundle/Controller/ProductOptionGroupAdminController.php line 180
at VopProductBundleControllerProductOptionGroupAdminController->createProductOptionGroupForm(object(ProductOptionGroup), 'option_group_form_0')
in /home/darius/PhpstormProjects/vop/src/Vop/ProductBundle/Controller/ProductOptionGroupAdminController.php line 162
at VopProductBundleControllerProductOptionGroupAdminController->getProductOptionGroupForms(object(Product))
in /home/darius/PhpstormProjects/vop/src/Vop/ProductBundle/Controller/ProductOptionGroupAdminController.php line 37
at VopProductBundleControllerProductOptionGroupAdminController->listAction()
in  line 
at call_user_func_array(array(object(ProductOptionGroupAdminController), 'listAction'), array())
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 144
at SymfonyComponentHttpKernelHttpKernel->handleRaw(object(Request), '1')
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 64
at SymfonyComponentHttpKernelHttpKernel->handle(object(Request), '1', true)
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php line 69
at SymfonyComponentHttpKernelDependencyInjectionContainerAwareHttpKernel->handle(object(Request), '1', true)
in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 185
at SymfonyComponentHttpKernelKernel->handle(object(Request))
in /home/darius/PhpstormProjects/vop/web/app_dev.php line 28

为什么会这样?

来自composer.json的奏鸣曲版本:

"Sonata-project/doctrine-orm-admin-bundle": "^2.2",

Symfony:

"symfony/symfony": "^2.8",

我尝试了各种方法。找不到如何执行此操作的正常教程。

问题就在这里

https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html#one-to-many-self-referencing

mappedBy="parent">

但是,"产品选项"实体中没有字段父级。

它仍然没有保存,但至少没有抛出这个错误,所以这是在回答这个问题。

相关内容

  • 没有找到相关文章

最新更新