4

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").

user3531149
  • 1,519
  • 3
  • 30
  • 48

1 Answers1

2

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.

acontell
  • 6,792
  • 1
  • 19
  • 32
  • no :(, now it throws an error and breaks the whole app, please check the edit on the OP (I cleared the cache too) – user3531149 Jan 22 '15 at 10:23
  • The problem you mentioned in the first place is solved, this is a new one. The error states it clearly: the `import_routing.yml` file you're using causes a circular reference. Do the proper changes to the `import_routing.yml` (you copied-pasted it, so no wonder it's causing the problem: one calls to the other and so on). – acontell Jan 22 '15 at 10:33
  • allright, since its a new error, I will create a new question if I don't manage to solve this, thanks for your help – user3531149 Jan 22 '15 at 10:45