How to tell symfony to load my custom routing.yml configuration

user3531149

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

acontell

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Symfony - There is no extension able to load the configuration - custom config

From Dev

How to declare both method in routing.yml Symfony2?

From Dev

How can I tell a Racket program to load optional configuration code?

From Dev

How can I tell a Racket program to load optional configuration code?

From Dev

Custom routing in load balancer

From Dev

Passing constructor arguments in routing yml file in Symfony

From Dev

How to load custom configuration file with twisted?

From Dev

How to Load Custom Spring Configuration Before CassandraDataAutoConfiguration

From Dev

If another server/website load image from my server, how to tell?

From Dev

Is it possible to load multiple resources in routing.yml?

From Dev

Symfony routing: how to redirect from UUID to custom slug

From Dev

Upstream Server Configuration is NULL in my Custom Load Balancing Module

From Dev

How to tell intel graphics to use my custom EDID file?

From Dev

Symfony2. There is no extension able to load the configuration. Custom configuration block

From Dev

Symfony2 routing.yml setting routing_frontend.yml and routing_backend.yml in same directory

From Dev

How Symfony routing works

From Dev

How can I tell the Web API / Castle Windsor routing engine to use a different database instance in my Repository?

From Dev

Hash escape in URL (routing.yml/path) Symfony 2

From Dev

Symfony2 routing.yml to external url

From Dev

Symfony where to initialize routes? (routing.yml or isnide controller)

From Dev

Symfony custom configuration - namespace issue

From Dev

Symfony custom configuration - namespace issue

From Dev

symfony how to use custom validators.yml file under MyBundle\Resources\translations

From Dev

Symfony 2 - Using custom service in routing expression

From Dev

How to use anchors in Symfony routing?

From Dev

how to get my configuration values in yml - using dropwizard (microservice) Jersey D.I @Injection?

From Dev

How can I use properties from a configuration (properties/yml) file in my Spring Boot application?

From Dev

How can I use properties from a configuration (properties/yml) file in my Spring Boot application?

From Dev

How to use my custom Symfony 3.0 Library/Bundle/HowIsCalled

Related Related

  1. 1

    Symfony - There is no extension able to load the configuration - custom config

  2. 2

    How to declare both method in routing.yml Symfony2?

  3. 3

    How can I tell a Racket program to load optional configuration code?

  4. 4

    How can I tell a Racket program to load optional configuration code?

  5. 5

    Custom routing in load balancer

  6. 6

    Passing constructor arguments in routing yml file in Symfony

  7. 7

    How to load custom configuration file with twisted?

  8. 8

    How to Load Custom Spring Configuration Before CassandraDataAutoConfiguration

  9. 9

    If another server/website load image from my server, how to tell?

  10. 10

    Is it possible to load multiple resources in routing.yml?

  11. 11

    Symfony routing: how to redirect from UUID to custom slug

  12. 12

    Upstream Server Configuration is NULL in my Custom Load Balancing Module

  13. 13

    How to tell intel graphics to use my custom EDID file?

  14. 14

    Symfony2. There is no extension able to load the configuration. Custom configuration block

  15. 15

    Symfony2 routing.yml setting routing_frontend.yml and routing_backend.yml in same directory

  16. 16

    How Symfony routing works

  17. 17

    How can I tell the Web API / Castle Windsor routing engine to use a different database instance in my Repository?

  18. 18

    Hash escape in URL (routing.yml/path) Symfony 2

  19. 19

    Symfony2 routing.yml to external url

  20. 20

    Symfony where to initialize routes? (routing.yml or isnide controller)

  21. 21

    Symfony custom configuration - namespace issue

  22. 22

    Symfony custom configuration - namespace issue

  23. 23

    symfony how to use custom validators.yml file under MyBundle\Resources\translations

  24. 24

    Symfony 2 - Using custom service in routing expression

  25. 25

    How to use anchors in Symfony routing?

  26. 26

    how to get my configuration values in yml - using dropwizard (microservice) Jersey D.I @Injection?

  27. 27

    How can I use properties from a configuration (properties/yml) file in my Spring Boot application?

  28. 28

    How can I use properties from a configuration (properties/yml) file in my Spring Boot application?

  29. 29

    How to use my custom Symfony 3.0 Library/Bundle/HowIsCalled

HotTag

Archive