routing.yml中的Symfony2 InvalidArgumentException

时间:2014-12-15 20:31:43

标签: symfony routing

我在src/Dive/LogbookBundle/Resources/config/routing.yml创建了这些路线:

login: 
   path:    /
   defaults: { _controller: DiveLogbookBundle:Security:login }

login_check: 
   pattern:   /login_check

random:
   path: /random/{limit}
   defaults: { _controller: DiveLogbookBundle:Random:index }

但是当我访问网页时,它会返回错误:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The definition of "login" in "/var/www/src/Dive/LogbookBundle/Resources/config/routing.yml" must be a YAML array.' in /var/www/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php:190
Stack trace: 
#0 /var/www/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(88): Symfony\Component\Routing\Loader\YamlFileLoader->validate(NULL, 'login', '/var/www/src/Di...') 
#1 /var/www/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php(106): Symfony\Component\Routing\Loader\YamlFileLoader->load('/var/www/src/Di...', NULL) 
#2 /var/www/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(155): Symfony\Component\Config\Loader\FileLoader->import('@DiveLogbookBun...', NULL, false, '/var/www/app/co...')
#3 /var/www/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(91): Symfony\Component\Routing\Loader\YamlFileLoader->parseImport(Object(Symfony in /var/www/app/bootstrap.php.cache on line 2986

有谁知道导致此问题的原因以及如何解决此问题?

提前致谢。

2 个答案:

答案 0 :(得分:1)

检查routing.yml的格式。 YAML对空格有严格的标准,不应包含任何制表符 - 所有缩进都必须用空格来完成。确保您已正确缩进所有内容,如果您的代码编辑器允许,可以对\t进行搜索和替换。

答案 1 :(得分:0)

仅供记录:可以使用linter立即发现问题php app/console lint:yaml <file_to_lint.yml>