找不到“GET/user/register"的路由:方法不允许(允许:POST) [英] No route found for "GET /user/register": Method Not Allowed (Allow: POST)
本文介绍了找不到“GET/user/register"的路由:方法不允许(允许:POST)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我去:http://mysite.com/web/app_dev.php/user/register
我得到:
MethodNotAllowedHttpException: No route found for "GET /user/register": Method Not Allowed (Allow: POST)
这是我的代码:
MainUserBundle_register:
pattern: /user/register/
defaults: { _controller: MainUserBundle:UserAuthWebService:register, _format:json}
requirements:
_method: POST
我的控制器是:
public function registerAction($email="test", $username="test", $password="test123")
{
//some code
}
为什么?
推荐答案
您可以将路由限制为仅匹配给定的 HTTP 方法.在您发布的代码中,路由只会匹配 POST
请求.您需要允许 POST
和 GET
,或者一起删除要求.
You can restrict a route to only match a given HTTP method. In the code you posted the route will only match POST
requests. You will need to allow POST
and GET
, or remove the requirement all together.
MainUserBundle_register:
pattern: /user/register/
defaults: { _controller: MainUserBundle:UserAuthWebService:register, _format:json}
requirements:
_method: POST|GET
http://symfony.com/doc/current/book/routing.html#adding-http-method-requirements
这篇关于找不到“GET/user/register"的路由:方法不允许(允许:POST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文