问题描述
我在使用symfony2和FOSUserBundle时遇到了一个非常奇怪的问题.
I am having a very strange problem with symfony2 and the FOSUserBundle.
我可以使用/en/logout登出,但不能使用/nl/logout或/fr/logout登出.
I can logout with /en/logout, but not with /nl/logout or /fr/logout.
当我尝试使用nl或fr登出时,我得到了:
When I try to logout with nl or fr I get:
You must activate the logout in your security firewall configuration.
尽管我配置了它.我似乎无法确定为什么/en/logout有效而其余的无效的原因.
Although I configured it. I can't seem to wrap my head why the /en/logout works and the rest doesn't.
这是我的代码:
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
encoders:
FOS\UserBundle\Model\UserInterface: sha512
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
check_path: fos_user_security_check
default_target_path: /%locale%/login
always_use_default_target_path: true
failure_path: /%locale%/login
logout:
path: /%locale%/logout
target: homepage
anonymous: true
routing.yml
user bundle > FOS
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
prefix: /{_locale}
requirements:
_locale: fr|nl|en
控制器
class LoginController extends Controller {
/**
* @Route("{_locale}/logout-test", name="logout", defaults={"_locale"="en"} , requirements = {"_locale" = "fr|en|nl"})
* @Template()
*/
public function logoutAction()
{
$test = "";
#throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
#return $this->redirect($this->generateUrl('homepage'));;
}
}
任何人都可以帮助我,或告诉我下一步去哪里吗?非常感谢
Can anyone help me out, or tell me where to look next? It would be much appreciated
推荐答案
在您的配置文件中,您需要使用路由而不是URL.如果以"/"开头,则将被视为URL,否则将被视为路由.如果使用路由而不是URL,则将自动处理语言环境.例如,这是我的security.yml配置:
In your configuration file, you need to use routes instead of URLs. If it starts with a "/" it will be treated as an URL, else it will be treated as a route. If you use routes instead of URLs, the locale will be taken care of automatically. For example, here is my security.yml configuration:
security:
public:
pattern: ^/
form_login:
login_path: fos_user_security_login
check_path: fos_user_security_check
provider: fos_userbundle
csrf_provider: form.csrf_provider
default_target_path: index
anonymous: true
logout:
path: fos_user_security_logout
target: index
这篇关于带前缀的FOSUserBundle注销不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!