I'm trying to achieve this http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html#more-advanced-loaders
I need the bundle routing to automatically activate itself when the bundle is registered
so I created this file into the path
src/Gabriel\AdminPanelBundle\Routing\AdvancedLoader.php
with the content
<?php
//namespace Acme\DemoBundle\Routing;
namespace Gabriel\AdminPanelBundle\Routing;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Routing\RouteCollection;
class AdvancedLoader extends Loader
{
public function load($resource, $type = null)
{
$collection = new RouteCollection();
$resource = '@GabrielAdminPanelBundle/Resources/config/import_routing.yml';
$type = 'yaml';
$importedRoutes = $this->import($resource, $type);
$collection->addCollection($importedRoutes);
return $collection;
}
public function supports($resource, $type = null)
{
return $type === 'advanced_extra';
}
}
I copied this configuration
gabriel_admin_panel:
resource: "@GabrielAdminPanelBundle/Controller/"
type: annotation
prefix: /superuser
from
/app/config/routing.yml
and pasted it into my own configuration file
/src/Gabriel/AdminPanelBundle/Resources/config/import_routing.yml
The problem:
Symfony2 completely ignores my AdvancedLoader.php file, I can put any syntax error in it and the site won't even throw an error, also the router:debug doesn't show the routes that are defined inside of the bundle unless I move the configuration back into its original router.yml file.
PS: clearing the cache doesn't change anything
Edit: when I add the service and the resource, this error appears
FileLoaderImportCircularReferenceException: Circular reference detected in "/app/config/routing_dev.yml" ("/app/config/routing_dev.yml" > "/app/config/routing.yml" > "." > "@GabrielAdminPanelBundle/Controller/" > "/app/config/routing_dev.yml").
Looks like you could have missed some steps in the process.
First one: did you define the service?
services:
gabriel.routing_loader:
class: Gabriel\AdminPanelBundle\Routing\AdvancedLoader
tags:
- { name: routing.loader }
Note the tag. As the documentation says:
Notice the tag routing.loader. All services with this tag will be marked as potential route loaders and added as specialized routers to the DelegatingLoader.
Second but very important because, as the documentation says, if you didn't add this lines your routing loader wouldn't be called:
# app/config/routing.yml
Gabriel_Extra:
resource: .
type: advanced_extra
The important part here is the type key. Its value should be "advanced_extra" in your case. This is the type which your AdvancedLoader
supports and this will make sure its load() method gets called. The resource key is insignificant for the AdvancedLoader
, so it is set to ".".
I think it will get loaded now.