如何将 security.yml 中的设置注入到服务中?
我有一个自定义服务,我想将 check_path
(来自 app/config/security.yml
)设置的值注入其中。在我的服务定义中,我尝试使用
arguments:
check_path: %security.firewalls.main.form_login.check_path%
但导致此错误:
服务“myService”依赖于不存在的参数 “security.firewalls.main.form_login.check_path”。
有谁知道如何让它发挥作用?
编辑
有一个解决方法,我可以首先在 parameters.ini
中定义一个变量,然后在 security.yml
中使用它并将其注入到我的服务中,但我想避免这种情况。需要在 parameters.ini
中“重新声明”变量似乎可能会变得混乱,特别是如果我稍后需要从 security.yml 注入更多设置。我不想每次需要发生这种情况时都必须在parameters.ini 中定义某些内容。
I have a custom service and I want to inject the value of the check_path
(from app/config/security.yml
) setting into it. In my service definition I tried using
arguments:
check_path: %security.firewalls.main.form_login.check_path%
but that results in this error:
The service "myService" has a dependency on a non-existent parameter
"security.firewalls.main.form_login.check_path".
Does anyone know how to get this to work?
Edit
There's a work around where I can first define a variable in parameters.ini
and then use it in security.yml
and inject it into my service, but I'd like to avoid that. Needing to 'redeclare' variables in parameters.ini
seems like it could get messy, especially if I later need to inject even more settings from security.yml. I wouldn't want to have to define something in parameters.ini each time this needs to happen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其添加到您的
parameters.yml
(或parameters.ini
- 然后使用=
而不是:
)文件中:然后转到您的
security.yml
并执行以下操作:然后使用它作为您的参数:
Add this to your
parameters.yml
(orparameters.ini
— then use=
instead of:
) file:Then go to your
security.yml
and do this:Then use this as your argument:
我不是 100% 确定,也许其他人可以确认,但尝试 @security.firewalls.main.form_login.check_path (用 @ 而不是引号来引用配置和服务)?
I'm not 100% sure, maybe someone else can confirm, but try @security.firewalls.main.form_login.check_path (with the @ instead of quotes to reference config and services)?