I would like to use a mix of yaml and php routing in a Symfony (3.3.8) app. I am pretty comfortable with yaml routing, so I used the bin/console doctrine:generate:crud command to see what PHP routing would look like. It generated a routing file that looks like
<?php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
$collection = new RouteCollection();
$collection->add('user_index', new Route(
'/',
array('_controller' => 'AppBundle:User:index'),
array(),
array(),
'',
array(),
array('GET')
));
// other CRUD routes...
return $collection;
This follows the format suggested on the Symfony docs, where you build up a RouteCollection with Routes and then return it.
When I try to run my app with this file in place, even if it is not referenced from my main routing.yml file, I get this error:
[Symfony\Component\Config\Exception\FileLoaderLoadException]
The autoloader expected class "AppBundle\Resources\config\routing\restful_resource" to be defined i
n file "/home/username/sites/appname/vendor/composer/../../src/AppBundle/Resources/config/routing/restfu
l_resource.php". The file was found but the class was not in it, the class name or namespace probab
ly has a typo in /home/username/sites/appname/app/config/services.yml (which is being imported from "/ho
me/username/sites/appname/app/config/config.yml").
[RuntimeException]
The autoloader expected class "AppBundle\Resources\config\routing\restful_resource" to be defined i
n file "/home/username/sites/appname/vendor/composer/../../src/AppBundle/Resources/config/routing/restfu
l_resource.php". The file was found but the class was not in it, the class name or namespace probab
ly has a typo.
Do I need to redesign this file to act like a class, going against the suggested format in the Symfony docs? Or do I need to somehow tell the autoloader to ignore this file so it doesn't try to find a class where there shouldn't be one?
restful_resource.phpis the name of file generated based on the entity. I'll try clearing the cache.Resourcesdirectory to be excluded from autowiring and everything went smoothly. Would you like to post your comment as an answer for the credit?