I have created a controller class under a module directory in Symfony 4. My bundle's routing file references it. My root's routing file includes the bundle's routing file.
However I get an error 500, "Error: the controller does neither exist as service nor as class".
Why?
root/src/MyBundle/Resources/config/routing.YML
route_name:
path: /test3
controller: MyBundle\Controller\ExportCsvController::exportProductInCsv
options:
expose: true
root/config/routes/my_custom_routes.YML
route_name:
resource: "@MyBundle/Resources/config/routing.yml"
prefix: /
root/src/MyBundle/Controller/ExportCsvController.PHP
<?php
namespace MyBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ExportCsvController extends Controller
{
public function exportProductInCsv(): Response
{
return new Response(
'<html><body>test</body></html>'
);
}
}
It was a problem of cache (Symfony cache). Solved with this command: php bin/console cache:clear --env=prod
. Now the content of the file root/src/MyBundle/Resources/config/routing.YML
is correctly taken into account :).