M
M
Mr Freeman2015-08-04 19:06:27
symfony
Mr Freeman, 2015-08-04 19:06:27

What is the best way to store roles in Silex with SecurityServiceProvider?

Hello to everyone who uses what schemes to store roles in Silex.
Here is part of the config file

'security.role_hierarchy' => array(
        'ROLE_ADMIN' => array(
            'ROLE_MANAGER'
        ),

        'ROLE_MANAGER' => array(
            'ROLE_SECTION_EDIT',
            'ROLE_SECTION_REMOVE',
        )
    )

Accordingly, if there are a bunch of roles, then this bunch can be confused, since you have to operate with strings. Yes, and editing then will be terrible. Can be stored in the yml of the config itself
user:
  roles:
    ROLE_ADMIN: "Администратор"
    ROLE_MANAGER: "Менеджер"
    ROLE_SECTION_EDIT: "Редактирование раздела"
    ROLE_SECTION_REMOVE: "Удаление раздела"

But in the config, you will also have to duplicate it later in order to pull out the role identifiers themselves.
Constants are possible, but this is also crap, like define('ROLE_ADMIN', 'ROLE_ADMIN');
Maybe there are some worthwhile beautiful solutions if roles are stored in the code, and not in the database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-08-04
@prototype_denis

Прикрутите транслятор и в твиг-шаблонах выводите примерно так.
На мой взгляд самое оптимальное решение.
Для хранения ролей в базе переопределяется сервис от Symfony, который будет "дёргать" роли из базы.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question