Symfony FOSRestBundle:未触发ExceptionController
config.yml:Symfony FOSRestBundle:未触发ExceptionController,symfony,fosrestbundle,Symfony,Fosrestbundle,config.yml: twig: debug: %kernel.debug% strict_variables: %kernel.debug% exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction' fos_rest: routing_loader: default_format: json view:
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'
fos_rest:
routing_loader:
default_format: json
view:
view_response_listener: force
force_redirects:
html: true
format_listener:
rules:
- { path: '^/api', fallback_format: json }
- { path: '^/', fallback_format: html }
param_fetcher_listener: force
body_listener: true
exception:
codes:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Symfony\Component\HttpKernel\Exception\NotFoundHttpException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
但是返回html:
...<h2><span>2/2</span> <abbr title="Symfony\Component\HttpKernel\Exception\NotFoundHttpException">NotFoundHttpException</abbr>: No route found for "GET /api/user/jFvms0rp%20"</h2>...
…2/2 NotFoundHttpException:找不到“GET/api/user/jFvms0rp%20”的路由。。。
如何将其转换为json?我解决了同样的问题: 这是我的配置:
fos_rest:
body_listener: true
view:
view_response_listener: force
format_listener:
rules:
- { path: '^/', fallback_format: json }
希望对您有所帮助,谢谢!他们应该把它放在文件里!我很想添加它&创建一个Pull请求,但我不完全确定每一行到底做什么?