FOSRestBundle 2.4 |如何加载休息类型路线
FOSRestBundle 2.4 | How to load rest type route
我将我的 FOSUserBundle 从 2.1 升级到 2.4,同时我将我的项目从 2.8 升级到 Symfony 3.4。
使用与之前相同的代码,以及这个 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_
我收到此错误:
Exception thrown when handling an exception
(Symfony\Component\Config\Exception\FileLoaderLoadException: The file
"/var/www/project/src/AppBundle/Resources/config/default.yml" does
not contain valid YAML in
/var/www/project/src/AppBundle/Resources/config/default.yml (which
is being imported from "/var/www/project/app/config/routing.yml").
Make sure there is a loader supporting the "rest" type.)
我哪里错了?我还尝试将 FOSRestBundle 降级到 2.3.1(我阅读了这个 )但没有任何变化。
问题是 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 的修复
对于最新的 (>3.0),您必须将路由类型从 rest 更改为 annotation。
我将我的 FOSUserBundle 从 2.1 升级到 2.4,同时我将我的项目从 2.8 升级到 Symfony 3.4。
使用与之前相同的代码,以及这个 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_
我收到此错误:
Exception thrown when handling an exception (Symfony\Component\Config\Exception\FileLoaderLoadException: The file "/var/www/project/src/AppBundle/Resources/config/default.yml" does not contain valid YAML in /var/www/project/src/AppBundle/Resources/config/default.yml (which is being imported from "/var/www/project/app/config/routing.yml"). Make sure there is a loader supporting the "rest" type.)
我哪里错了?我还尝试将 FOSRestBundle 降级到 2.3.1(我阅读了这个
问题是 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 的修复
对于最新的 (>3.0),您必须将路由类型从 rest 更改为 annotation。