Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <?php
  2.  
  3. // src/AppBundle/Menu/MenuBuilder.php
  4. namespace AppBundle\Menu;
  5.  
  6. use Knp\Menu\FactoryInterface;
  7. use Symfony\Component\DependencyInjection\ContainerAware;
  8.  
  9. class MenuBuilder extends ContainerAware
  10. {
  11. public function mainMenu(FactoryInterface $factory, array $options)
  12. {
  13. $menu = $factory->createItem('root');
  14. $menu->setChildrenAttribute('class', 'nav navbar-nav');
  15.  
  16. $menu->addChild('Projects', array('route' => 'acme_hello_projects'))
  17. ->setAttribute('icon', 'fa fa-list');
  18.  
  19. $menu->addChild('Employees', array('route' => 'acme_hello_employees'))
  20. ->setAttribute('icon', 'fa fa-group');
  21.  
  22. return $menu;
  23. }
  24.  
  25. public function userMenu(FactoryInterface $factory, array $options)
  26. {
  27. $menu = $factory->createItem('root');
  28. $menu->setChildrenAttribute('class', 'nav navbar-nav navbar-right');
  29.  
  30. /*
  31. You probably want to show user specific information such as the username here. That's possible! Use any of the below methods to do this.
  32.  
  33. if($this->container->get('security.context')->isGranted(array('ROLE_ADMIN', 'ROLE_USER'))) {} // Check if the visitor has any authenticated roles
  34. $username = $this->container->get('security.context')->getToken()->getUser()->getUsername(); // Get username of the current logged in user
  35.  
  36. */
  37. $menu->addChild('User', array('label' => 'Hi visitor'))
  38. ->setAttribute('dropdown', true)
  39. ->setAttribute('icon', 'fa fa-user');
  40.  
  41. $menu['User']->addChild('Edit profile', array('route' => 'acme_hello_profile'))
  42. ->setAttribute('icon', 'fa fa-edit');
  43.  
  44. return $menu;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement