【问题标题】:Gedmo Tree didn't manage implement itGedmo Tree 没有管理实现它
【发布时间】:2016-04-06 07:01:20
【问题描述】:

我正在尝试使类别/菜单动态更新链接和管理面板中的所有内容。我尝试从 gedmo 实现 Tree,但即使在我花费数小时查看文档后也无法得到孩子。我也想使用 knp 菜单包。 有人可以帮我实现它并向我解释 lft、rgt、root、树级别是什么以及为什么我应该在什么时候使用它们?

这是我的方法:

public function createAdminMenu(array $options)
{
    $menu_item = $this->em->getRepository('AppBundle:MenuItem');
    $menu = $this->factoryInterface->createItem('root');

    $rootNodes = $menu_item->getRootNodes();

    //var_dump($rootNodes);
    $node = $menu_item->findOneByName('User');
    var_dump($menu_item->getChildren());
    foreach($rootNodes as $node) {
        if($node->getDisplay())
        {
            $menu->addChild($node->getName(), array('uri' => $node->getUri()));

            $child_node = $node->getChildren($node);
            //var_dump($child_node);
            foreach($child_node as $child)
            {
                //$menu[$node->getName()] = $menu->addChild($child->getName());
            }
        }
    }


    return $menu;
}

【问题讨论】:

    标签: php symfony doctrine-orm tree


    【解决方案1】:

    这样解决了:

        $repo = $this->em->getRepository('AppBundle:MenuItem');
    
        $nodes = $repo->findByRootNodes($menuId);
    
        foreach ($nodes as $node) {
            if ($node->getDisplay()) {
                $menu->addChild($node->getName(), ['uri' => $node->getRoute()])
                    ->setAttribute('dropdown', $node->getDropDown());
                if ($node->getDisplayChildren()) {
                    $children = $repo->children($node);
                    if($children)
                    {
                        foreach ($children as $child)
                        {
                            if ($child->getDisplay())
                            {
                                $menu[$node->getName()]->addChild($child->getName(), ['uri' => $child->getRoute()])
                                    ->setAttribute('divider_prepend', $child->getDividerPrepend())
                                    ->setAttribute('divider_append', $child->getDividerAppend());
                            }
                        }
                    }
                }
            }
        }
        return $menu;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      • 2014-03-14
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多