1

I'm having the same problem symfony2 is describing here

This comes in handy when you have a bundle but don't want to manually add the routes for the bundle to app/config/routing.yml. This may be especially important when you want to make the bundle reusable

TLDR; im trying to implement a custom Route Loader using this part of the symfony2 documentation http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html#more-advanced-loaders

However it doesn't seem to be working, the route cannot be found;

This is what I've tried so far: The loader:

<?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/routing.yml';
        $type = 'yaml';

        $importedRoutes = $this->import($resource, $type);

        $collection->addCollection($importedRoutes);

        return $collection;
    }

    public function supports($resource, $type = null)
    {
        return $type === 'advanced_extra';
    }
}

here is my routing.yml

located in: src/Gabriel/AdminPanelBundle/Resources/config/routing.yml

the routing.yml

gabriel_admin_panel:
    resource: "@GabrielAdminPanelBundle/Controller/"
    type:     annotation
    prefix:   /superuser

The Routes of the bundle can't be found unless I put the Routes back in the main app/config/routing.yml file, how to fix this?

Edit:

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
  • Your code looks fine. Did you clear cache? You can use `app/console router:debug` to check all routes available – marcoshoya Jan 21 '15 at 13:18
  • I cleared the cache and router:debug doesn't show the route, I put that configuration above 'gabriel_admin_panel' from the main app/config/routing.yml directly into the Gabriel/AdminPanelBundle/Resources/config/routing.yml is this right? – user3531149 Jan 21 '15 at 13:39
  • Yes, it is. After some tests, I found the answer. Take a look below – marcoshoya Jan 21 '15 at 18:34

1 Answers1

1

You must also configure service

# src/Gabriel/AdminPanelBundle/Resources/config/services.yml
your_bundle.routing_loader:
    class: Gabriel\AdminPanelBundle\Routing\AdvancedLoader
    tags:
        - { name: routing.loader }

And routing file

# app/config/routing.yml
YourBundle_extra:
    resource: .
    type: advanced_extra
marcoshoya
  • 214
  • 1
  • 5