Примечание: неопределенный индекс: родительский при добавлении множественного выбора в админке Sonata

Я делаю аналогично этому ответу:

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] Symfony\Component\Debug\Exception\ContextErrorException: 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 Symfony\Component\Debug\ErrorHandler->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' => 'Vop\ProductBundle\Entity\ProductOption', 'cascade' => array(), 'orphanRemoval' => false, 'fetch' => '2', 'type' => '4', 'inversedBy' => null, 'isOwningSide' => false, 'sourceEntity' => 'Vop\ProductBundle\Entity\ProductOption', '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 Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getOneToManyStatement(array('fieldName' => 'dependsOn', 'mappedBy' => 'parent', 'targetEntity' => 'Vop\ProductBundle\Entity\ProductOption', 'cascade' => array(), 'orphanRemoval' => false, 'fetch' => '2', 'type' => '4', 'inversedBy' => null, 'isOwningSide' => false, 'sourceEntity' => 'Vop\ProductBundle\Entity\ProductOption', '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 Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadOneToManyCollection(array('fieldName' => 'dependsOn', 'mappedBy' => 'parent', 'targetEntity' => 'Vop\ProductBundle\Entity\ProductOption', 'cascade' => array(), 'orphanRemoval' => false, 'fetch' => '2', 'type' => '4', 'inversedBy' => null, 'isOwningSide' => false, 'sourceEntity' => 'Vop\ProductBundle\Entity\ProductOption', '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 Doctrine\ORM\UnitOfWork->loadCollection(object(PersistentCollection))
        in /home/darius/PhpstormProjects/vop/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php line 697

    at Doctrine\ORM\PersistentCollection->doInitialize()
        in /home/darius/PhpstormProjects/vop/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php line 214

    at Doctrine\ORM\PersistentCollection->initialize()
        in /home/darius/PhpstormProjects/vop/vendor/doctrine/collections/lib/Doctrine/Common/Collections/AbstractLazyCollection.php line 157

    at Doctrine\Common\Collections\AbstractLazyCollection->toArray()
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php line 49

    at Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer->transform(object(PersistentCollection))
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 1146

    at Symfony\Component\Form\Form->normToView(object(PersistentCollection))
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 353

    at Symfony\Component\Form\Form->setData(object(PersistentCollection))
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57

    at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(ProductOption), object(RecursiveIteratorIterator))
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 386

    at Symfony\Component\Form\Form->setData(object(ProductOption))
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57

    at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(PersistentCollection), object(RecursiveIteratorIterator))
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 386

    at Symfony\Component\Form\Form->setData(object(PersistentCollection))
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57

    at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(ProductOptionGroup), object(RecursiveIteratorIterator))
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 386

    at Symfony\Component\Form\Form->setData(object(ProductOptionGroup))
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 478

    at Symfony\Component\Form\Form->initialize()
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 226

    at Symfony\Component\Form\FormBuilder->getForm()
        in /home/darius/PhpstormProjects/vop/src/Vop/ProductBundle/Controller/ProductOptionGroupAdminController.php line 180

    at Vop\ProductBundle\Controller\ProductOptionGroupAdminController->createProductOptionGroupForm(object(ProductOptionGroup), 'option_group_form_0')
        in /home/darius/PhpstormProjects/vop/src/Vop/ProductBundle/Controller/ProductOptionGroupAdminController.php line 162

    at Vop\ProductBundle\Controller\ProductOptionGroupAdminController->getProductOptionGroupForms(object(Product))
        in /home/darius/PhpstormProjects/vop/src/Vop/ProductBundle/Controller/ProductOptionGroupAdminController.php line 37

    at Vop\ProductBundle\Controller\ProductOptionGroupAdminController->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 Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 64

    at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php line 69

    at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
        in /home/darius/PhpstormProjects/vop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 185

    at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
        in /home/darius/PhpstormProjects/vop/web/app_dev.php line 28

Почему это так?

См. также:  Разверните свое приложение Symfony на Heroku

Версия сонаты из composer.json:

«соната-проект / доктрина-орм-админ-связка»: «^ 2.2»,

Symfony:

«symfony / symfony»: «^ 2.8»,

Я пробовал разные способы. Не могу найти нормальный учебник, как это сделать.

Понравилась статья? Поделиться с друзьями:
IT Шеф
Комментарии: 1
  1. Darius.V

    Проблема была здесь

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

    mappedBy = «родительский»

    Но в сущности ProductOption не было родительского поля.

    Тем не менее, это не сохранение, но, по крайней мере, не выдача этой ошибки, так что это ответ на этот вопрос.

Добавить комментарий

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: