无法加载资源"。"在routing.yml中写完之后

时间:2016-04-06 09:21:23

标签: symfony

我做了一个自动写入routing.yml的命令。 我的问题是,当我尝试浏览其中一条路线时

api:
    resource: "."
    type:     "api"
    prefix: /api

我得到了这个例外

  

无法加载资源"。"

我尝试添加一个缓存:清除我的命令,但我得到了同样的例外。

1 个答案:

答案 0 :(得分:0)

我添加了一个缓存预热,它在命令终止后运行,Symfony将路由转储到生成的代码中。

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 }