User
У вас запятая после «думаю» пропущена.
/** * @ORM\ManyToOne(targetEntity="Menu", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") */ private $parent; /** * @ORM\OneToMany(targetEntity="Menu", mappedBy="parent") */ private $children; /** * Constructor */ public function __construct() { $this->children = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Set parent * * @param \Common\MenuBundle\Entity\Menu $parent * @return Menu */ public function setParent(\Common\MenuBundle\Entity\Menu $parent = null) { $this->parent = $parent; return $this; } /** * Get parent * * @return \Common\MenuBundle\Entity\Menu */ public function getParent() { return $this->parent; } /** * Add children * * @param \Common\MenuBundle\Entity\Menu $children * @return Menu */ public function addChildren(\Common\MenuBundle\Entity\Menu $children) { $this->children[] = $children; return $this; } /** * Remove children * * @param \Common\MenuBundle\Entity\Menu $children */ public function removeChildren(\Common\MenuBundle\Entity\Menu $children) { $this->children->removeElement($children); } /** * Get children * * @return \Doctrine\Common\Collections\Collection */ public function getChildren() { return $this->children; }
public function mainMenu(FactoryInterface $factory, array $options) { $menuItems = $this->container->get('menu')->getMainMenu(); $menu = $factory->createItem('root'); $this->setCurrentItem($menu); $menu->setChildrenAttribute('class', 'nav nav-justified'); $menu->setExtra('currentElement', 'active'); foreach($menuItems as $item) { if ($item->getParent()) { $em = $this->container->get('doctrine')->getEntityManager(); $parent = $em->getRepository('CommonMenuBundle:menu')->find($item->getParent()); $menu[$parent->getTitle()] ->setChildrenAttribute('class', 'dropdown-menu dropdown-menu-large row') ->setAttribute("class", "dropdown dropdown-large") ->addChild($item->getTitle(), array('uri' => $item->getRoute())) ->setAttribute("class", "col-sm-6") ; } else { $menu->addChild($item->getTitle(), array('uri' => $item->getRoute())); } } return $menu; }
Просветите…
habrastorage.org/storage3/68a/4b9/e27/68a4b9e279c9e0424cc7e6a472470e71.png
1) Добавил в сущность «Menu» следующее:
2) Изменил Builder:
В результате получилось вложенное меню:
А на фронтенде в моем случае отображается так:
2) Спасибо, Dropbox и Google Drive пока удовлетворяют все потребности
2) Скорость закачки печальна
Программирую на php. Мощности вполне хватает