0

To my Symfony version 3.3 project at app/config/routing.yml file I have put:

AppBundle:
    resource: '@AppBundle/Resources/config/routing.php'
    prefix: /
    type: 'php'

And on src/AppBundle/Resources/config/routing.php I have put the following:

use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

$collection = new RouteCollection();
$collection->add('blog_list', new Route('/blog', array(
    '_controller' => 'AppBundle:Blog:list',
)));
$collection->add('blog_show', new Route('/blog/{slug}', array(
    '_controller' => 'AppBundle:Blog:show',
)));

return $collection;

But I get the following error:

The autoloader expected class "AppBundle\Resources\config\routing" to be defined in file "/home/pcmagas/Kwdikas/myblog/vendor/composer/../../src/AppBundle/Resources/config/routing.php". The file was found but the class was not in it, the class name or namespace probably has a typo in /home/pcmagas/Kwdikas/myblog/app/config/services.yml (which is being imported from "/home/pcmagas/Kwdikas/myblog/app/config/config.yml").

Do you know fellows how to load the routes via a "external" php file? I mean in the very same way you load via yml the routes to load them via php.

As fas as I know according to: http://symfony.com/doc/current/routing.html you can use php file to load the routes.

Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164

1 Answers1

-1

May be its because you don't have a namespace in your routing.php file.

You have to put at the beginning of the file :

namespace AppBundle\Resources\config;
Fabien Salles
  • 1,101
  • 15
  • 24
  • Nope still asks for a class. – Dimitrios Desyllas Oct 12 '17 at 10:14
  • Maybe you can only configure php routes like that in the default file (app/config/routing.yml|php) and the only solution to add others routes in php is to create a [custom route loader](https://symfony.com/doc/current/routing/custom_route_loader.html) – Fabien Salles Oct 12 '17 at 10:21
  • @FabienSalles - At the risk of being harsh, maybe you should stop guessing and start reading the docs and do a bit of testing. – Cerad Oct 13 '17 at 01:33
  • The docs only have examples for the file `app/config/routing.*` configure in the config.yml. So it's fine. I already read it ! – Fabien Salles Oct 13 '17 at 11:04