Magento - 管理字段的默认值

Dav*_*vid 12 magento

是否可以(通过编程或xml配置)为文本字段admin config选项设置默认值?如果是这样,怎么样?

Muk*_*ain 36

您可以通过模块的config.xml文件向admin config选项添加默认值.通过admin config选项,我知道您的意思是配置设置选项(系统 - >配置).

假设您有以下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>
Run Code Online (Sandbox Code Playgroud)

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

<default>
    <mysection>
        <mygroup>                
            <myfield>My Default Value</myfield>         
        </mygroup>      
    </mysection>
</default>
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.

有关详细说明,请参阅: - http://alanstorm.com/magento_default_system_configuration_values