路由:对#34;方法的要求"必须是一个字符串

时间:2016-01-21 23:36:49

标签: php symfony

我目前正在将我的一个项目从Symfony2更新到Symfony3。大部分工作已经完成,但我不明白某种错误。

对于路由配置文件,我阅读了告诉我编写此配置的官方文档(http://symfony.com/doc/current/book/routing.html#adding-http-method-requirements):

corbins_characters_new_character:
    path: /characters/new
    defaults: { _controller: CorbinsCharacterBundle:Character:new }
    requirements:
        methods: [GET]

corbins_characters_new_character:
    path: /characters
    defaults: { _controller: CorbinsCharacterBundle:Character:create }
    requirements:
        methods: [POST]

但是当我这样做时,我有以下错误:

Routing requirement for "methods" must be a string in C:\Developpement\Symfony2\Corbins_V3\src\Corbins\CharacterBundle/Resources/config/routing.yml (which is being imported from "C:\Developpement\Symfony2\Corbins_V3\app/config\routing.yml").

InvalidArgumentException: Routing requirement for "methods" must be a string.
 - in vendor\symfony\symfony\src\Symfony\Component\Routing\Route.php at line 571

我打算为Symfony创建一个新问题,但首先我想在这里寻求帮助:D!

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

在Doc中,它表示方法不是需求的子项,它只是父键。

corbins_characters_new_character:
    path: /characters
    defaults: { _controller: CorbinsCharacterBundle:Character:create }
    methods: [POST]

请你用yml配置检查http://symfony.com/doc/current/book/routing.html#adding-http-method-requirements