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

  • SEARCH
  • Home
  • 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 7525563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:35:04+00:00 2026-05-30T03:35:04+00:00

My project has many roles: admin, HR, manager, employee. How do I implement it

  • 0

My project has many roles: admin, HR, manager, employee. How do I implement it in a generalized way in Symfony2 such that new roles can be added in future?

  • 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-05-30T03:35:05+00:00Added an answer on May 30, 2026 at 3:35 am

    Symfony2 represents authenticated users using The UserInterface interface.

    This interface asks you to implement the getRoles method, which returns all the roles a user has.

    Based on how you implement this UserInterface, you can grab these roles from a database, a web service, or whatever you want.

    One simple way to provide these users is the in-memory provider:

    # app/config/security.yml
    security:
        # ...
        providers:
            in_memory:
                users:
                    ryan:  { password: bb87a29949f3a1ee0559f8a57357487151281386, roles: 'ROLE_USER' }
                    admin: { password: 74913f5cd5f61ec0bcfdb775414c2fb3d161b620, roles: [ 'ROLE_ADMIN', 'ROLE_RH'] }
    

    Another way is to use the EntityProvider. For more details look at this cookbook entry.

    In this last example, user roles are statically stored in a harcoded array, but they could come from another table, using table associations. That’s how it’s done in the FOSUserBundle.

    You can even define a role hierarchy:

    # app/config/security.yml
    security:
        role_hierarchy:
            ROLE_ADMIN:       ROLE_USER
            ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
    

    So that any user that has role ROLE_ADMIN has also inherited the role ROLE_USER.

    For more info look at the docs.

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

Sidebar

Related Questions

I am adding MVC to a project that has MANY legacy webform pages. This
Given that every software project only has so many programmer-hours dedicated to it, how
We have a sub-project 'commonUtils' that has many generic code-snippets used across the parent
I've inherited a flash project (my first) that has many existing symbols in the
My project has many dependencies that I've referenced from other projects. I am now
ok i have a project which has many gridview in its pages... now i
I'm building WPF client application. I'm following MVC pattern. The project solution has many
In a project, one of my entities is House which has many enumeration properties
I would like to be able to model a many-to-many relationship that has extra
My project has many reader and writer classes. I started implementing IDisposable, but I

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.