Skip to content

Commit

Permalink
Poniendo el menu como servicio
Browse files Browse the repository at this point in the history
  • Loading branch information
Osukaru committed Oct 2, 2011
1 parent e6fcf88 commit 0efab54
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 44 deletions.
Empty file modified src/SFM/WebsiteBundle/DependencyInjection/Configuration.php 100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions src/SFM/WebsiteBundle/DependencyInjection/SFMWebsiteExtension.php 100755 → 100644
Expand Up @@ -22,7 +22,7 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
21 changes: 0 additions & 21 deletions src/SFM/WebsiteBundle/Menu/Builder.php

This file was deleted.

33 changes: 33 additions & 0 deletions src/SFM/WebsiteBundle/Menu/MenuBuilder.php
@@ -0,0 +1,33 @@
<?php

namespace SFM\WebsiteBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\HttpFoundation\Request;

class MenuBuilder
{
private $factory;

/**
* @param FactoryInterface $factory
*/
public function __construct(FactoryInterface $factory)
{
$this->factory = $factory;
}

public function createMenuPrincipal(Request $request)
{
$menu = $this->factory->createItem('root');
$menu->setCurrentUri($request->getRequestUri());

$menu->addChild('Inicio', array('route' => 'inicio'));
$menu->addChild('Blog', array('route' => 'blog'));
$menu->addChild('Proyectos', array('route' => 'proyectos'));
$menu->addChild('Personas', array('route' => 'personas'));


return $menu;
}
}
20 changes: 0 additions & 20 deletions src/SFM/WebsiteBundle/Resources/config/services.xml

This file was deleted.

13 changes: 13 additions & 0 deletions src/SFM/WebsiteBundle/Resources/config/services.yml
@@ -0,0 +1,13 @@
services:
sfm_website.menu_builder:
class: SFM\WebsiteBundle\Menu\MenuBuilder
arguments: ["@knp_menu.factory"]

sfm_website.menu.principal:
class: Knp\Menu\MenuItem # the service definition requires setting the class
factory_service: sfm_website.menu_builder
factory_method: createMenuPrincipal
arguments: ["@request"]
scope: request # needed as we have the request as a dependency here
tags:
- { name: knp_menu.menu, alias: principal } # The alias is what is used to retrieve the menu
2 changes: 1 addition & 1 deletion src/SFM/WebsiteBundle/Resources/views/layout.html.twig
Expand Up @@ -33,7 +33,7 @@
</section>
<!--start menu-->
<nav>
{{ knp_menu_render('SFMWebsiteBundle:Builder:menuPrincipal') }}
{{ knp_menu_render('principal') }}
</nav>
<!--end menu-->
</header>
Expand Down

0 comments on commit 0efab54

Please sign in to comment.