代码之家  ›  专栏  ›  技术社区  ›  NicolaPez

FOSRestBundle 2.4 |如何加载休息型路由

  •  2
  • NicolaPez  · 技术社区  · 6 年前

    与以前的代码相同 yml 文件:

    # app/config/routing.yml
    api_request_backend:
        type: rest
        prefix: /api
        resource: "@AppBundle/Resources/config/default.yml"
    

    -

    # AppBundle/Resources/config/default.yml
    api:
        type: rest    # This resource will have RESTful routes
        prefix:
        resource: "@AppBundle\Controller\ApiController"
        name_prefix: api_
    apiV2:
        type: rest    # This resource will have RESTful routes
        prefix: /v2
        resource: "@AppBundle\Controller\ApiV2Controller"
        name_prefix: api_v2_
    api_user:
        type: rest    # This resource will have RESTful routes
        prefix:
        resource: "@AppBundle\Controller\ApiUserController"
        name_prefix: api_
    

    我收到这个错误:

    处理异常时引发异常 (Symfony\Component\Config\Exception\FileLoaderLoadException:文件 中不包含有效的YAML /var/www/project/src/AppBundle/Resources/config/default.yml(其中 确保有支持“rest”类型的加载程序。)

    我错在哪里?我还尝试将FOSRestBundle降级到2.3.1(我读了这篇文章) here )但一切都没变。

    1 回复  |  直到 6 年前
        1
  •  2
  •   IndyDevGuy    4 年前

    对于最新的(>3.0)必须将管线类型从“静止”更改为“注释”。

        2
  •  1
  •   cezar    6 年前

    问题是无效的YAML。以下工作:

    # app/config/routing.yml
    api_request_backend:
        type: rest
        prefix: /api
        resource: '@AppBundle/Resources/config/default.yml' 
    

    # AppBundle/Resources/config/default.yml
    api:
        type: rest    # This resource will have RESTful routes
        resource: '@AppBundle\Controller\ApiController'
        name_prefix: api_
    

    xabbuh 为了解决这个问题