Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:31:58+00:00 2026-06-18T10:31:58+00:00

I am using the FOSUser Bundle for Symfony… My question is; I have two

  • 0

I am using the FOSUser Bundle for Symfony… My question is;
I have two different group of users…. For example; Teachers and Students, which it is set when they register to the system. (using the user table of FOSUser Bundle)

After a successful login, I want to user to go to the correct landing page.. So
If the user is a teacher, I want the user to go to /teacher and for student to /student.

What is the best way to approach this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:31:59+00:00Added an answer on June 18, 2026 at 10:31 am

    You need an event listener to listen for an login event. Then you can route the client to different pages based on their roles.

    services.yml:

    services:
        login_listener:
            class: Acme\UserBundle\Listener\LoginListener
            arguments: [@security.context, @doctrine]
            tags:
                - { name: kernel.event_listener, event: security.interactive_login }
    

    LoginListener:

    <?php
    
    namespace Acme\UserBundle\Listener;
    
    use Symfony\Component\EventDispatcher\Event;
    use Symfony\Component\Security\Core\SecurityContext;
    use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.1.x
    // use Symfony\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.0.x
    
    /**
     * Custom login listener.
     */
    class LoginListener
    {
        /** @var \Symfony\Component\Security\Core\SecurityContext */
        private $securityContext;
    
        /** @var \Doctrine\ORM\EntityManager */
        private $em;
    
        /**
         * Constructor
         * 
         * @param SecurityContext $securityContext
         * @param Doctrine        $doctrine
         */
        public function __construct(SecurityContext $securityContext, Doctrine $doctrine)
        {
            $this->securityContext = $securityContext;
            $this->em              = $doctrine->getEntityManager();
        }
    
        /**
         * Do the magic.
         * 
         * @param  Event $event
         */
        public function onSecurityInteractiveLogin(Event $event)
        {
            if ($this->securityContext->isGranted('ROLE_1')) {
                // redirect 1
            }
    
            if ($this->securityContext->isGranted('ROLE_2')) {
                // redirect 2
            }
    
            // do some other magic here
            $user = $this->securityContext->getToken()->getUser();
    
            // ...
        }
    }
    

    From: http://www.metod.si/login-event-listener-in-symfony2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a symfony 2.1 project using FOSUserBundle. The bundle is installed correctly. All
I am building a web application with Symfony 2, using the FOSUserBundle bundle. Users
I use Symfony 2. I have so far 2 bundles. The first bundle is
I am using Symfony2 and I have users and roles already stored in my
I'm using Symfony 2.1 for a project and FOSUserBundle to manage the users. I'm
I have an example where I am trying to create an AJAX login using
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
I'm using Symfony 2.1 for a project and trying to use FOSUserBundle to manage
I'm using FOSUserBundle to manager users, now I'm trying to secure some controller actions
Our application is using Symfony 2.0 and MongoDB with FOSUserBundle for user management. Client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.