Magento自定义模块如何在config.xml中存储变量 [英] Magento Custom Module How to store variable in config.xml
问题描述
我有一个自定义模块,工作很好,但我想能够在配置中存储变量,所以我可以在我的代码中使用它们。 (例如一个默认的错误消息)
我想我可以通过使用Mage :: getStoreConfig('/ some / path / here'但我不知道如何将它们添加到模块config.xml(myname / mymodule / etc / config.xml),以便我可以在我的代码中使用它们。
<任何人都有线索?
谢谢!
阅读这些两个文章应该提供您需要添加自己的自定义配置变量的信息,这些变量会自动为您提供输入值在管理员。
如果您要为新的配置变量设置默认值,则有一个顶级的 config.xml
节点命名为 default
,这将让你这样做。请考虑以下
< config>
<! - ... - >
< default>
< web>
< default>
< cms_home_page>首页< / cms_home_page>
< cms_no_route>无路由< / cms_no_route>
< cms_no_cookies> enable-cookies< / cms_no_cookies>
< front> cms< / front>
< no_route> cms / index / noRoute< / no_route>
< show_cms_breadcrumbs> 1< / show_cms_breadcrumbs>
< / default>
< / web>
< cms>
< wysiwyg>
< enabled> enabled< / enabled>
< / wysiwyg>
< / cms>
< / default>
<! - ... - >
< / config>
config.xml中的此结构
设置默认以下配置变量的值
web / default / cms_home_page
web / default / cms_no_route
web / default / cms_no_cookies
web / default / front
web / default / no_route
web / default / show_cms_breadcrumbs
cms / wysiwyg / enabled
I have a custom module that is working just fine but I would like to be able to store variables in the config so I can use them in my code. (For example a default error message)
I think I can access them by using Mage::getStoreConfig('/some/path/here'); but I don't know how to add them to the modules config.xml (myname/mymodule/etc/config.xml) so that I can use them in my code?
Anyone have a clue? Thanks!
Reading these two articles should give you the information you need to add your own custom configuration variable, which will automatically give you a UI to enter values in the Admin.
If you want to set a default value for your new configuration variables, there's a top level config.xml
node named default
which will let you do that. Consider the following
<config>
<!-- ... -->
<default>
<web>
<default>
<cms_home_page>home</cms_home_page>
<cms_no_route>no-route</cms_no_route>
<cms_no_cookies>enable-cookies</cms_no_cookies>
<front>cms</front>
<no_route>cms/index/noRoute</no_route>
<show_cms_breadcrumbs>1</show_cms_breadcrumbs>
</default>
</web>
<cms>
<wysiwyg>
<enabled>enabled</enabled>
</wysiwyg>
</cms>
</default>
<!-- ... -->
</config>
This structure in config.xml
sets default values for the following config variables
web/default/cms_home_page
web/default/cms_no_route
web/default/cms_no_cookies
web/default/front
web/default/no_route
web/default/show_cms_breadcrumbs
cms/wysiwyg/enabled
这篇关于Magento自定义模块如何在config.xml中存储变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!