douluolan9101
2018-05-11 15:27
浏览 68
已采纳

配置用户和角色时出现Symfony php错误

I am trying to configure a set of users and roles in my php program. I've followed the tutorial on the synfony website but I recieve the following error:

(1/1) InvalidTypeException Invalid type for path "security.access_control.0.path". Expected scalar, but got array. Hint: use the urldecoded format

Security.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: ~

Update

I found the problem thanks to Andrew Vakhniuk. I forgot to put a ':' after path under access control.

图片转代码服务由CSDN问答提供 功能建议

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

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

Security.yml:

   #要开始使用安全性,请查看文档:
#https://symfony.com/doc/current/security.html
security:
 providers:
 in_memory:
 memory:
 users:\  n inkoper:
密码:inkoper 
角色:'ROLE_INKOPER'
 
 access_control:
  -  {path'^ / *',roles:[ROLE_INKOPER]} 
 
编码器:
 Symfony \ Component \  Security \ Core \ User \ User:明文
 
防火墙:
#禁用资产和分析器的身份验证,根据您的需要进行调整
 dev:
 pattern:^ /(_(profiler | wdt)|  css | images | js)/ 
 security:false 
 
 main:
匿名:〜
#激活不同的方式来验证
 
#https://symfony.com/doc/current/security。  HTML#A-配置知识,您的用户 s-will-authenticate 
 http_basic:〜
 
#https://symfony.com/doc/current/security/form_login_setup.html
 #form_login:〜
   
  
 

更新

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

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题