Skip to content

Commit

Permalink
Merge pull request #247 from KnpLabs/docs-example
Browse files Browse the repository at this point in the history
Adding an example using the container
  • Loading branch information
stof committed Jan 9, 2015
2 parents 5dccd04 + 9107808 commit 9f56a1a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Resources/doc/index.md
Expand Up @@ -108,9 +108,15 @@ class Builder extends ContainerAware
$menu = $factory->createItem('root');

$menu->addChild('Home', array('route' => 'homepage'));
$menu->addChild('About Me', array(
'route' => 'page_show',
'routeParameters' => array('id' => 42)

// access services from the container!
$em = $this->container->get('doctrine')->getManager();
// findMostRecent and Blog are just imaginary examples
$blog = $em->getRepository('AppBundle:Blog')->findMostRecent();

$menu->addChild('Latest Blog Post', array(
'route' => 'blog_show',
'routeParameters' => array('id' => $blog->getId())
));
//You can also add sub level's to your menu's as follows
$menu['About Me']->addChild('Edit profile', array('route' => 'edit_profile'));
Expand Down

0 comments on commit 9f56a1a

Please sign in to comment.