Symfony 中的 YML 文件 - 您能否获得向下超过 1 级的关联数组?
我有大量数据想要存储在 /apps/frontend/modules/builder/config/module.yml
中。
我让它看起来像:
all:
series_options:
compact:
name: Compact
description: Something small.
enabled: 1
large:
name: Large
description: Bit bigger.
enabled: 0
在 actions.class 中,如果我写这个:
sfConfig::get('mod_builder_series_options_compact');
我得到这个
Array
(
[name] => Compact
[description] => Something small.
[enabled] => 1
)
完美。但我想这样写:
sfConfig::get('mod_builder_series_options');
这给出了NULL
。
有什么方法可以让我将完整的关联数组返回到其完整深度,以便我可以迭代不同的选项?
I have a load of data I want to store in /apps/frontend/modules/builder/config/module.yml
.
I have it looking something like:
all:
series_options:
compact:
name: Compact
description: Something small.
enabled: 1
large:
name: Large
description: Bit bigger.
enabled: 0
In the actions.class if I write this:
sfConfig::get('mod_builder_series_options_compact');
I get this
Array
(
[name] => Compact
[description] => Something small.
[enabled] => 1
)
Perfect. But I want to write this:
sfConfig::get('mod_builder_series_options');
Which gives NULL
.
Is there any way I can get this to return the full associative array to its full depth so I can iterate through the different options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在其名称前添加一个带有点的级别,以强制数组处于特定级别:
现在您应该能够通过以下方式访问您的设置:
请记住,模块配置只能在其定义的模块中访问。
You can add a level with a dot before its name to force array on certain level:
Now you should be able to access your settings with:
Remember that module configuration is only accessible in the module it is defined.
典型的是,当我一发布答案时,答案就打在我脸上......
返回:
猜测 sfConfig 并不是真正用于此目的,而 sfYaml 看起来确实是这样!
希望这对其他人有帮助!
Typical, as soon as I resort to posting the answer hits me in the face...
Returns:
Guessing that sfConfig wasnt really meant for this purpose, where sfYaml certainly looks like it was!
Hope this helps someone else!