【问题标题】:Magento - default value for admin fieldMagento - 管理字段的默认值
【发布时间】:2011-05-01 00:21:44
【问题描述】:

是否可以(通过编程或 xml 配置)为文本字段管理配置选项设置默认值?如果有,怎么做?

【问题讨论】:

    标签: magento


    【解决方案1】:

    您可以通过模块的 config.xml 文件为管理配置选项添加默认值。通过管理员配置选项,我理解您的意思是配置设置选项(系统 -> 配置)。

    假设,您有以下 system.xml 文件。 System.xml 文件是添加管理配置选项所必需的。

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
       <sections>         
            <mysection translate="label" module="mymodule">
                <label>My Section</label>
                <tab>catalog</tab>
                <frontend_type>text</frontend_type>
                <sort_order>110</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store> 
                <groups>
                    <mygroup translate="label" module="mymodule">
                        <label>My Group</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>99</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                        <fields>
                            <myfield translate="label comment">
                                <label>My Field</label>                         
                                <frontend_type>text</frontend_type>
                                <sort_order>1</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>1</show_in_store>
                            </myfield>                      
                        </fields>
                    </mygroup>
                </groups>           
            </mysection>            
        </sections>
    </config>
    

    现在,要为管理配置选项添加默认值,您需要在模块的 config.xml 文件中编写以下内容。

    <default>
        <mysection>
            <mygroup>                
                <myfield>My Default Value</myfield>         
            </mygroup>      
        </mysection>
    </default>
    

    希望这会有所帮助。

    详细解释可以参考:-http://alanstorm.com/magento_default_system_configuration_values

    【讨论】:

    • 这似乎对我不起作用。我已经刷新了我的缓存、存储缓存、登录和注销、清除了浏览器缓存。我还必须做什么才能使默认值起作用?
    【解决方案2】:
    <default>
        <catalog><!-- tag of the system.xml section -->
            <frontend><!-- tag of the system.xml group -->
                <name_of_your_field>4</name_of_your_field><!-- tag of the system.xml field -->
            </frontend>
        </catalog>
    </default>
    

    【讨论】:

      猜你喜欢
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      相关资源
      最近更新 更多