I made a command that automatically writes this in routing.yml .
api:
resource: "."
type: "api"
prefix: /api
My problem is that when I try to access it http://localhost:8000/api
I get this exception
Cannot load resource "."
I tried to add a cache:clear to my command but I get the same exception.
Are you on 1.x or master?
If you're on master, the type should be api_platform.
I'm using v1.1.0
Then it seems like the problem lies elsewhere. Have you loaded the bundle in AppKernel?
If you still need help, it'd be best if you can provide more details, preferably a sample project reproducible in which the problem is reproducible.
To debug route loading it's a good idea to run app/console debug:router -vvv.
Here is my test scenario :
routing.yml is empty
I run my command that writes different configurations
Now routing.yml contains
api:
resource: "."
type: "api"
prefix: /api
I go to localhost:8000/api , I get Cannot load resource "." . ( no route in debug:router )
I run cache:clear then I try again It works .
That's expected behavior. Symfony dumps routes into generated code during cache warmup.
I added a cache warmup that runs after the command termination that way Symfony dumps routes into generated code .
class TerminateListener {
public function onConsoleTerminate(ConsoleTerminateEvent $event) {
if ($event->getCommand()->getName() == ('my:command')) {
$app = new Application();
$cache_clear_command = $event->getCommand()->getApplication()->find('cache:warmup');
$cache_clear_command->setApplication($app);
$event->getOutput()->setVerbosity('VERBOSITY_QUIET');
$cache_clear_command->run($event->getInput(), $event->getOutput());
}
}
}
services:
warmup.listener:
class:TerminateListener
tags:
- { name: kernel.event_listener, event: console.terminate , method: onConsoleTerminate }