我在symfony2和FOSUserBundle中遇到了一个非常奇怪的问题。
我可以使用/en/logout登出,但不能使用/nl/logout或/fr/logout登出。
当我尝试使用nl或fr登出时,我得到:
You must activate the logout in your security firewall configuration.
虽然我配置了它。我似乎无法确定为什么/en/logout有效而其余的无效的原因。
这是我的代码:
安全性
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
Controller
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'));;
}
}
谁能帮我,或告诉我下一步去哪里?不胜感激
最佳答案
在您的配置文件中,您需要使用路由而不是URL。如果以“/”开头,则将被视为URL,否则将被视为路由。如果使用路由而不是URL,则将自动处理语言环境。例如,这是我的security.yml配置:
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
关于symfony - 带前缀的FOSUserBundle注销不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14941989/