我们使用Easy Extends覆盖了Sonata的RegistrationController
。在我们生成的appDevProjectContainerUrlMatcher
类中,我们现在有以下几行:
if ($pathinfo === '/password/reset') {
return array ( '_controller' => 'Application\\Sonata\\UserBundle\\Controller\\RegistrationController::passwordResetAction', '_route' => 'fos_user_password_reset',);
}
我可以打开我的自定义RegistrationController
类,并看到以下内容:
/**
* @return RedirectResponse
*/
public function passwordResetAction()
{
...
}
现在的问题是:我想让这个动作只接受POST请求。如果没有路径注释,我该怎么做? (我找不到显式定义此路由的任何地方,不包括上面提到的自动生成的类。)
===
编辑:这是在Symfony 2.7应用程序中。
你可以验证它是否是Post请求,如:
if ($request->isMethod('post')) { // Uppercase request method:POST
// your code
}
getMethod()获取请求“预期”方法。
也许你可以尝试这个:
$request->getMethod()