Gedmo Tree getPath Error: Node is not related to this repository 500 Internal Server Error - InvalidArgumentException

Gedmo Tree getPath Error: Node is not related to this repository 500 Internal Server Error - InvalidArgumentException

我遇到错误:

Node is not related to this repository
500 Internal Server Error - InvalidArgumentException

更新 1:如果我设置树并不重要 repository with traits or extend abstract repository 错误是一样的。

更新 2:完整堆栈跟踪 http://pastebin.com/TtaJnyzf

我想从数据库输出 html 具有树结构的树,特别是 我需要获取从根到选定节点的路径 。据我了解,这是通过 getPath() 函数完成的。

我正在使用:

为了管理树结构。

为了设置树结构,我使用了关于 Symfony.com [2] 的文档,然后是关于 GitHub [3]、[4]、[5]、[6] 的文档。

到目前为止,我在数据库中有一个树结构,我得到 html 树,如下所示:

<?php

namespace AppBundle\Controller;

use AppBundle\Entity\Category;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class TreeController extends Controller
{
    /**
     * @Route("/tree", name="tree")
     */
    public function treeAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();

        $repo = $em->getRepository('AppBundle:Category');
        $options = array(
            'decorate' => true,
            'rootOpen' => '<ul>',
            'rootClose' => '</ul>',
            'childOpen' => '<li>',
            'childClose' => '</li>',
            nodeDecorator' => function($node)
            {
                return '<a href="/some_path/...">'. $node['title'] .'</a>';
            }
        );

        $htmlTree = $repo->childrenHierarchy(
            null, /* starting from root nodes */
            false, /* false: load all children, true: only direct */
            $options
        );

        return $this->render('tree/tree_show.html.twig', array('project_tree' => $htmlTree));
    }
}

我更改了两行以显示从树元素的根到所选项目的路径

nodeDecorator' => function($node) use ($repo)
{
    return '<a href="/project_path/'. implode('/', $repo->getPath($node)) .'">'. $node['title'] .'</a>';
}

如 [7] 和 [8] 中所示,函数 getPath() 应该 return 从根到所选项目的元素数组存在。

我认为问题可能在于此代码块:

$repo->getPath($node)

请指教。 感谢您的时间和知识。

成功了!

以下是所需的更改:

而不是

nodeDecorator' => function($node) use ($repo)
{
    return '<a href="/project_path/'. implode('/', $repo->getPath($node)) .'">'. $node['title'] .'</a>';
}

应该写

'nodeDecorator' => function($node) use ($repo)
{
    return '<a href="/project_path/'. @implode('/', $repo->getPath($repo->findOneBy(array('id' => $node['id'])))) .'">'. $node['title'] .'</a>';
}

并在类别 class 中添加

public function __toString()
{
    return $this->getTitle();
}

就是这样,现在应该显示每个节点的路径。