首页 > 解决方案 > 配置用户和角色时 Symfony php 错误

问题描述

我正在尝试在我的 php 程序中配置一组用户和角色。我已按照 synfony 网站上的教程进行操作,但收到以下错误:

(1/1) InvalidTypeException 路径“security.access_control.0.path”的类型无效。预期的标量,但得到了数组。提示:使用 urldecoded 格式

安全.yml:

# To get started with security, check out the documentation:
# https://symfony.com/doc/current/security.html
security:
    providers:
        in_memory:
            memory:
                users:
                    inkoper:
                        password: inkoper
                        roles: 'ROLE_INKOPER'

    access_control:
        - { path '^/*', roles: [ROLE_INKOPER] }

    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            anonymous: ~
            # activate different ways to authenticate

            # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
            http_basic: ~

            # https://symfony.com/doc/current/security/form_login_setup.html
            #form_login: ~

更新

感谢 Andrew Vakhniuk,我发现了这个问题。我忘了在访问控制下的路径后加上一个':'。

标签: phpsymfonysecurity

解决方案


将您的访问控制更改为

   - { path: '^/', roles: ROLE_INKOPER }

推荐阅读