【问题标题】:PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "NULL"PropertyAccessor 需要对象或数组的图形来操作,但它发现类型为“NULL”
【发布时间】:2018-01-08 13:12:04
【问题描述】:

我在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。 提前谢谢!

【问题讨论】:

  • 您的 _constructor 工作得如何?在您的数据库中,链接表的 id 是 register ?
  • @Jeremy 你太棒了!这就对了! __constructor 不行。

标签: php symfony doctrine sonata


【解决方案1】:

看看那里:Sonata PostPersist

在这里你可以找到一个 Sonata 构造函数,它可能会对你有所帮助。它可能比使用 _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();
    }
}

希望它有用。如果您有任何问题,请提出。

【讨论】:

  • 谢谢!你的例子很有用。
  • 如果您得到了答案,您可以将此帖子保存为已解决。好像有人正在寻找类似问题的答案,他会知道他可以在这里找到他的问题的答案。
【解决方案2】:

对我来说,当我将它初始化为 arrayArrayCollection 时,它就起作用了。

public function __construct() {
   $this->conditions = [];
}

Symfony 抛出异常,因为如果没有初始化,它就不能迭代它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    相关资源
    最近更新 更多