简体   繁体   中英

Issue with sonata_type_collection

I have included a related model in my admin as follows

->add('parameters', 'sonata_type_collection', array(
        'type_options' => array(
            // Prevents the "Delete" option from being displayed
            'delete' => false,
             )
    ), array(
        'edit' => 'inline',
        'inline' => 'table',
        'sortable' => 'position',
    ))

The child admin is included and I can add a new row. However, when I try to add a second child, I get the following error:

PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "NULL" while trying to traverse path "parameters[0]" at property "0". 

I cannot explain what is happening, I am using symfony 2.7.3 and using dev-master branch of Admin bundle. I don't know whether this has been reported, I have tried to check in the issues list but haven't seen it

You got that Exception because you forgot to initialize the childrens collection in the parent constructor.

// src/AppBundle/Entity/Parent.php

function __construct() {
    $this->children = new \Doctrine\Common\Collections\ArrayCollection();
}

In your example, children must be parameters .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM