Symfony3.3 重定向到路由不走定义的路径
Symfony3.3 Redirect to route does not take the defined path
我正在使用 FOSUserBundle,我只想在它的所有路由前加上一个“/account”。
我有一个继承自 FOSUserBundle 的 UserBundle:
<?php
//UserBundle.php
namespace UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class UserBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
在我的路由中使用前缀定义了这个控制器:
# app/config/routing.yml
user:
resource: "@UserBundle/Resources/config/routing.yml"
prefix: /account
并在我的包中导入 FOS 路由:
#UserBundle/config/routing.yml
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
prefix: /user
我试图通过 XML(覆盖父文件)或通过 yml 逐个文件覆盖所有路径。我总是有明确定义的路线(bin/console debug:route --show-controllers 的输出):
fos_user_security_login GET|POST ANY ANY /account/login FOSUserBundle:Security:login
fos_user_security_check POST ANY ANY /account/login_check FOSUserBundle:Security:check
fos_user_security_logout GET|POST ANY ANY /account/logout FOSUserBundle:Security:logout
fos_user_profile_show GET ANY ANY /account/profile/ FOSUserBundle:Profile:show
fos_user_profile_edit GET|POST ANY ANY /account/profile/edit FOSUserBundle:Profile:edit
fos_user_registration_register GET|POST ANY ANY /account/register/ FOSUserBundle:Registration:register
fos_user_registration_check_email GET ANY ANY /account/register/check-email FOSUserBundle:Registration:checkEmail
fos_user_registration_confirm GET ANY ANY /account/register/confirm/{token} FOSUserBundle:Registration:confirm
fos_user_registration_confirmed GET ANY ANY /account/register/confirmed FOSUserBundle:Registration:confirmed
fos_user_resetting_request GET ANY ANY /account/resetting/request FOSUserBundle:Resetting:request
fos_user_resetting_send_email POST ANY ANY /account/resetting/send-email FOSUserBundle:Resetting:sendEmail
fos_user_resetting_check_email GET ANY ANY /account/resetting/check-email FOSUserBundle:Resetting:checkEmail
fos_user_resetting_reset GET|POST ANY ANY /account/resetting/reset/{token} FOSUserBundle:Resetting:reset
fos_user_change_password GET|POST ANY ANY /account/profile/change-password FOSUserBundle:ChangePassword:changePassword
但是当我重定向到路由 'fos_user_security_login' 时,我被重定向到“/login”而不是“/account/login”
如果你知道为什么,我很乐意知道:p
编辑:这是 security.yml
中的防火墙和 ACLS
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
check_path: /account/login_check
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
logout:
path: /account/logout
target: /account/login
anonymous: true
access_control:
# authorise to login and reset password for everyone
- { path: ^/account, role: IS_AUTHENTICATED_ANONYMOUSLY }
可能问题出在
#UserBundle/config/routing.yml
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
prefix: /user
它可能覆盖了您使用默认定义的登录路由。尝试在路由文件中添加:
login:
path: /account/login
defaults: { _controller: FOSUserBundle:Security:login }
login_check:
path: /account/login_check
defaults: { _controller: FOSUserBundle:Security:check }
导入所有路由后,或仅从 FOSUserBundle 添加您需要的路由。您可以从 vendor 目录下的 FOSUserBundle/Resources/config/routing/all.xml 中获取它们。
我找到问题了,我是因为权限管理不好。
我尝试访问 /
并将其重定向到 /account/login
,但我没有为 /
路径设置 ACL,这意味着它会自动将我重定向到 /login
,给我问题出在我的印象中。
我正在使用 FOSUserBundle,我只想在它的所有路由前加上一个“/account”。 我有一个继承自 FOSUserBundle 的 UserBundle:
<?php
//UserBundle.php
namespace UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class UserBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
在我的路由中使用前缀定义了这个控制器:
# app/config/routing.yml
user:
resource: "@UserBundle/Resources/config/routing.yml"
prefix: /account
并在我的包中导入 FOS 路由:
#UserBundle/config/routing.yml
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
prefix: /user
我试图通过 XML(覆盖父文件)或通过 yml 逐个文件覆盖所有路径。我总是有明确定义的路线(bin/console debug:route --show-controllers 的输出):
fos_user_security_login GET|POST ANY ANY /account/login FOSUserBundle:Security:login
fos_user_security_check POST ANY ANY /account/login_check FOSUserBundle:Security:check
fos_user_security_logout GET|POST ANY ANY /account/logout FOSUserBundle:Security:logout
fos_user_profile_show GET ANY ANY /account/profile/ FOSUserBundle:Profile:show
fos_user_profile_edit GET|POST ANY ANY /account/profile/edit FOSUserBundle:Profile:edit
fos_user_registration_register GET|POST ANY ANY /account/register/ FOSUserBundle:Registration:register
fos_user_registration_check_email GET ANY ANY /account/register/check-email FOSUserBundle:Registration:checkEmail
fos_user_registration_confirm GET ANY ANY /account/register/confirm/{token} FOSUserBundle:Registration:confirm
fos_user_registration_confirmed GET ANY ANY /account/register/confirmed FOSUserBundle:Registration:confirmed
fos_user_resetting_request GET ANY ANY /account/resetting/request FOSUserBundle:Resetting:request
fos_user_resetting_send_email POST ANY ANY /account/resetting/send-email FOSUserBundle:Resetting:sendEmail
fos_user_resetting_check_email GET ANY ANY /account/resetting/check-email FOSUserBundle:Resetting:checkEmail
fos_user_resetting_reset GET|POST ANY ANY /account/resetting/reset/{token} FOSUserBundle:Resetting:reset
fos_user_change_password GET|POST ANY ANY /account/profile/change-password FOSUserBundle:ChangePassword:changePassword
但是当我重定向到路由 'fos_user_security_login' 时,我被重定向到“/login”而不是“/account/login”
如果你知道为什么,我很乐意知道:p 编辑:这是 security.yml
中的防火墙和 ACLSfirewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
check_path: /account/login_check
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
logout:
path: /account/logout
target: /account/login
anonymous: true
access_control:
# authorise to login and reset password for everyone
- { path: ^/account, role: IS_AUTHENTICATED_ANONYMOUSLY }
可能问题出在
#UserBundle/config/routing.yml
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
prefix: /user
它可能覆盖了您使用默认定义的登录路由。尝试在路由文件中添加:
login:
path: /account/login
defaults: { _controller: FOSUserBundle:Security:login }
login_check:
path: /account/login_check
defaults: { _controller: FOSUserBundle:Security:check }
导入所有路由后,或仅从 FOSUserBundle 添加您需要的路由。您可以从 vendor 目录下的 FOSUserBundle/Resources/config/routing/all.xml 中获取它们。
我找到问题了,我是因为权限管理不好。
我尝试访问 /
并将其重定向到 /account/login
,但我没有为 /
路径设置 ACL,这意味着它会自动将我重定向到 /login
,给我问题出在我的印象中。