我在 AssignmentTypeAdmin 中有这个方法:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('code', 'text')
->add('label', 'text', array('label'=>'Libellé'))
->add('assignHierarchyNode.label', 'text', array('label' => 'Noeud hiérarchique'))
->add('assignPortfolioType.portfolioTypeLabel', null, array('label' => 'Type de portefeuille'))
->add('assignGeoHierarchyNodeType.label', null, array('label' => 'Type de noeud hiérarchique'));
}
在 AssignmentType 类中:
/**
* @ORM\ManyToOne(targetEntity="HierarchyManagerBundle\Entity\HierarchyNode")
* @ORM\JoinColumn(name="assign_hierarchy_node_id", referencedColumnName="id", nullable=FALSE)
*/
private $assignHierarchyNode;
在 HierarchyNode 类中:
...
/**
* @var string
* @Gedmo\TreePathSource
* @ORM\Column(name="label", type="string", length=255)
*/
private $label;
...
还有 get 和 set 方法。
我的问题是我收到此错误,我不知道为什么:
PropertyAccessor 需要对象或数组的图形来操作,但它在尝试遍历属性“label”处的路径“assignHierarchyNode.label”时发现类型“NULL”。
为此,我使用 Symfony 3.1、Doctrine 2.5.2、Sonata Bundle。
先感谢您!
最佳答案
看看那里:Sonata PostPersist
在这里你可以找到一个奏鸣曲构造函数,它可能对你有帮助。它可能比使用 _constructor 更好。你可以在下面找到一个例子。
public function postPersist($client)
{
$em = $this->getConfigurationPool()->getContainer()->get('doctrine.orm.entity_manager');
if ($client instanceof Client )
{
$test = new Test();
$test->setClient($client);
$test->setSurname($client->getSurname());
$test->setFirstname($client->getFirstname());
$em->persist($test);
$em->flush();
}
}
希望它有用。如果您有任何问题,请提问。
关于php - PropertyAccessor 需要对象或数组的图形来操作,但它发现类型 "NULL",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45441709/