Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 2,登录后FOSUserBundle重定向_Php_Symfony_Redirect_Login_Fosuserbundle - Fatal编程技术网

Php Symfony 2,登录后FOSUserBundle重定向

Php Symfony 2,登录后FOSUserBundle重定向,php,symfony,redirect,login,fosuserbundle,Php,Symfony,Redirect,Login,Fosuserbundle,我想知道登录后如何设置重定向?我有两个控制器,一个用于未经授权的普通用户,另一个用于管理员用户,我希望我的登录表单在以管理员身份登录后立即重定向到来自管理员控制器的路径。 我的控制器的小部件: 正规的 管理员: /** * Buty controller. * @Route("/buty") */ class ButyController extends Controller { /** * Lists all Buty entities. * * @Route("/", name=

我想知道登录后如何设置重定向?我有两个控制器,一个用于未经授权的普通用户,另一个用于管理员用户,我希望我的登录表单在以管理员身份登录后立即重定向到来自管理员控制器的路径。 我的控制器的小部件: 正规的

管理员:

/**
 * Buty controller.
 * @Route("/buty")
 */
class ButyController extends Controller
{
/**
 * Lists all Buty entities.
 *
 * @Route("/", name="app_admin_buty_index")
 * @Method("GET")
 */
public function indexAction()
{
    $em = $this->getDoctrine()->getManager();

    $shoes = $em->getRepository('ShoeShopBundle:Buty')->findAll();

    return $this->render('ShoeShopBundle:Admin/Buty:index.html.twig', array(
        'shoes' => $shoes,
    ));
}
我的路线.yml

app_admin:
  resource: "@ShoeShopBundle/Controller/Admin/"
  type: "annotation"
  prefix: "/admin"

app_front:
  resource: "@ShoeShopBundle/Controller/Front/"
  type: "annotation"
  prefix: "/"

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
还有我的安全

security:
encoders:
    FOS\UserBundle\Model\UserInterface: bcrypt

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    main:
        pattern: ^/
        form_login:
            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:       true
        anonymous:    true

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin, role: ROLE_ADMIN }
安全性:
编码器:
FOS\UserBundle\Model\UserInterface:bcrypt
角色层次结构:
角色\管理员:角色\用户
角色超级管理员:角色管理员
供应商:
fos_用户包:
id:fos\u user.user\u provider.username
防火墙:
主要内容:
模式:^/
表格(u)登入:
提供商:fos_用户包
csrf_令牌_生成器:security.csrf.token_管理器
#如果您使用的是Symfony<2.8,请改用以下配置:
#csrf\u提供程序:form.csrf\u提供程序
注销:正确
匿名:是的
访问控制:
-{path:^/login$,角色:已通过身份验证\u匿名}
-{path:^/register,role:IS_AUTHENTICATED_ANONYMOUSLY}
-{路径:^/正在重置,角色:是否以匿名方式进行身份验证}
-{路径:^/admin,角色:role_admin}
提前感谢您的所有建议


编辑:下面链接中的问题不适用于FOSUserBundle。

在您的控制器中添加此功能

    /**
     * @Route("/", name="app_admin_buty_index")
     */
    public function redirectAction()
    {
        $authChecker = $this->container->get('security.authorization_checker');

        if ($authChecker->isGranted('ROLE_USER')) {
            return $this->render('the name of your user homePage', array());

        } elseif ($authChecker->isGranted('ROLE_ADMIN ')) {
            return $this->render('the name of your admin homePage ',array());

        } else {
            return $this->render('userLogin.html.twig', array());
        }
    }
在防火墙部分和主要部分的security.yml中,我添加了这个

 always_use_default_target_path: false 
 default_target_path: /app_admin_buty_index

在一个控制器中添加此功能

    /**
     * @Route("/", name="app_admin_buty_index")
     */
    public function redirectAction()
    {
        $authChecker = $this->container->get('security.authorization_checker');

        if ($authChecker->isGranted('ROLE_USER')) {
            return $this->render('the name of your user homePage', array());

        } elseif ($authChecker->isGranted('ROLE_ADMIN ')) {
            return $this->render('the name of your admin homePage ',array());

        } else {
            return $this->render('userLogin.html.twig', array());
        }
    }
在防火墙部分和主要部分的security.yml中,我添加了这个

 always_use_default_target_path: false 
 default_target_path: /app_admin_buty_index
可能的重复可能的重复