Last active
December 10, 2015 20:58
-
-
Save rybakit/4491556 to your computer and use it in GitHub Desktop.
RybakitNavigationBundle full example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Twig/AcmeExtension.php | |
namespace Acme\DemoBundle\Twig\Extension; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
class AcmeExtension extends \Twig_Extension | |
{ | |
private $container; | |
public function __construct(ContainerInterface $container) | |
{ | |
$this->container = $container; | |
} | |
public function getGlobals() | |
{ | |
return array('nav' => $this->container->get('acme.navigation')); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Controller/FooController.php | |
namespace Acme\DemoBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
class FooController extends Controller | |
{ | |
/** | |
* @Template() | |
*/ | |
public function barAction() | |
{ | |
// an alternative way to pass a navigation array to a tempate | |
return array('nav_sidebar' => $this->container->get('acme.navigation.sidebar')); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Resources/config/services.xml ---> | |
... | |
<service id="acme.navigation_builder" class="Acme\DemoBundle\Navigation\NavigationBuilder"> | |
<argument type="service" id="request_stack" /> | |
<argument type="service" id="router" /> | |
<argument type="service" id="event_dispatcher" /> | |
</service> | |
<service id="acme.navigation" class="Rybakit\Bundle\NavigationBundle\Navigation\Item" factory-service="acme.navigation_builder" factory-method="buildNavigation" /> | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment