From 8a9a63905ebc8b0d482dc9bd8995502cab2f505c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 7 Apr 2017 23:05:42 +0200 Subject: [PATCH] add dependency injection / load routes --- source/development/useful-snippets.rst | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/source/development/useful-snippets.rst b/source/development/useful-snippets.rst index 435790b0f..98d07a1d1 100644 --- a/source/development/useful-snippets.rst +++ b/source/development/useful-snippets.rst @@ -5,6 +5,44 @@ Useful snippets ############### +Dependency Injection +******************** + +Configure route automatically +============================= + +Add the route for the current bundle automatically on the main app. + +.. code-block:: php + + namespace Chill\MyBundle\DependencyInjection; + + use Symfony\Component\DependencyInjection\ContainerBuilder; + use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; + + + class ChillMyExtension extends Extension implements PrependExtensionInterface + { + // ... + + public function prepend(ContainerBuilder $container) + { + $this->prependRoutes($container); + + } + + public function prependRoutes(ContainerBuilder $container) + { + //add routes for custom bundle + $container->prependExtensionConfig('chill_main', array( + 'routing' => array( + 'resources' => array( + '@ChillMyBundle/Resources/config/routing.yml' + ) + ) + )); + } + Security ********