Gedmo Tree 没有设法实现它
Gedmo Tree didn't manage implement it
我正在尝试使类别/菜单动态化以更新管理面板中的链接和所有内容。我尝试从 gedmo 实现 Tree,但即使我花了几个小时查看文档也无法获得 children。我也想使用 knp 菜单包。
有人可以帮我实现它并向我解释什么是 lft、rgt、root、tree 的级别以及为什么我应该在什么时候使用它们?
这是我的方法:
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;
}
这样解决的:
$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;
我正在尝试使类别/菜单动态化以更新管理面板中的链接和所有内容。我尝试从 gedmo 实现 Tree,但即使我花了几个小时查看文档也无法获得 children。我也想使用 knp 菜单包。 有人可以帮我实现它并向我解释什么是 lft、rgt、root、tree 的级别以及为什么我应该在什么时候使用它们?
这是我的方法:
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;
}
这样解决的:
$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;