Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP+Symfony] KnpMenuBundle z bazy
dopelganger
post 20.03.2015, 14:59:33
Post #1





Grupa: Zarejestrowani
Postów: 236
Pomógł: 0
Dołączył: 27.10.2012

Ostrzeżenie: (0%)
-----


cześć

mam w DefaultController.php menu pobierane z bazki:

  1.  
  2. /**
  3. *
  4. * @Template()
  5. */
  6. public function menuAction(){
  7. $em = $this->getDoctrine()->getManager();
  8. $entities = $em->getRepository('TextPageBundle:Page')->findBy(array('view'=>1));
  9. return array('entities' => $entities);
  10. }


i chciałbym zaczytać menu do KnpMenuBundle, no i nie wiem jak smile.gif prosze o pomoc

TextPageBundle/Menu/Builder.php;

  1. class Builder extends ContainerAware
  2. {
  3. public function mainMenu(FactoryInterface $factory, array $options)
  4. {
  5. $menu = $factory->createItem('root');
  6. $em = $this->container->get('doctrine')->getManager();
  7. $m = $em->getRepository('TextPageBundle:Page')->findBy(array('view'=>1),array('seq'=>'ASC'));
  8. $menu->addChild('menu_dynamic', array('route'=>'menu_show','routeParameters'=>array('slug'=>$m->getSlug())));
  9. return $menu;
  10. }
  11. }


a szablon menu w default/ menu.hml.twig:

  1. <nav class="menu">
  2. {{ knp_menu_render('TextPageBundle:Builder:mainMenu') }}
  3. </nav>
  4.  


Ten post edytował dopelganger 21.03.2015, 08:42:30
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 23.06.2025 - 20:51