从其他模块访问 symfony 模块配置
我正在使用 symfony 1.4 开发一个有点复杂的、主要是 AJAX 应用程序。为我的模块使用一些自定义属性对我来说非常有帮助,这些属性是我在 module.yml 配置文件中定义的,例如:
all:
first_property: value1
second_property: value2
等。
这些属性主要用于格式化由javascript,使用从我的模块返回的 JSON 值。例如 - 在我的主模块(用于渲染基本视图)控制器中,我想使用类似的东西:
// In frontend/modules/main
$property sfConfig::get('mod_somemodule_someproperty');
它不会工作,因为默认情况下,模块的属性无法通过 sfConfig 在模块外部访问: :get() 方法。
我的问题是:
是否可以以某种方式访问这些属性?
如果没有 - 如果有人建议一种不同的方式,我可以为我的模块指定一些重复属性并从外部控制器访问它们,我将非常感激。
谢谢。
I am developing a somewhat complex, mostly AJAX application using symfony 1.4. It would be very helpful for me to use some custom properties for my modules, which I defined in the module.yml configuration files, for example:
all:
first_property: value1
second_property: value2
etc.
This properties would be used mainly for formatting views generated by javascript, using JSON values returned from my modules. For example - in my main module (used to render the base view) controller I wanted to use something like that:
// In frontend/modules/main
$property sfConfig::get('mod_somemodule_someproperty');
It won't work because by default properties of a module are not accessible outside of the module by the sfConfig::get() method.
My question is:
Is it possible to somehow access these properties?
If not - I would be really grateful if somebody suggested a different way in which I could specify some recurring attributes for my modules and the access them from an outside controller.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果要访问模块外部的模块配置,为什么不让配置成为app级别的配置呢?
如果您想在应用程序之间共享应用程序级别的配置,则该配置应该是项目级别的。
If you want to access the module configuration outside the module, why not make the configuration be app level configuration?
And if you want to share the app level configuration between apps, the configuration should be project level.
我猜您熟悉
app.yml
配置?它用于存储整个应用程序的配置设置,而不仅仅是所选模块。这是存储更多通用设置的地方......但是,话虽如此。您可以使用 sfYaml 类打开您选择的 module.yml 。像这样的东西(伪代码)
或者,您可以将项目
all
键与所选环境合并。I guess you're familiar with the
app.yml
config? Which is used to store configuration settings through the whole application, not just the selected module. This is the place to store more generic settings...But, that said. You could just open the
module.yml
of your choice with thesfYaml
class. Something like this (pseudo code)Optionally, you could merge the items
all
key with the selected environment.每当我想在模块外部共享任何代码时,我都会将其放入插件中,任何模块都可以从中获取它。我不知道这是否适用于属性,但我怀疑是这样。
Whenever I've wanted to share any code outside a module, I've just put it in a plugin, from which any module can get at it. I don't know that this works for properties, but I suspect so.