开发者

Magento - default value for admin field

Is it possible (via programming or xml configuration) to have a default value 开发者_高级运维for a text field admin config option? If so, how?


You can add default value to admin config option through config.xml file of your module. By admin config option, I understand that you mean configuration settings options (System -> Configuration).

Suppose, you have the following system.xml file. System.xml file is necessary to add admin configuration options.

<?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>

Now, to add default value to the admin configuration options, you need to write the following in config.xml file of your module.

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

Hope this helps.

For detail explanation, you may refer to:- http://alanstorm.com/magento_default_system_configuration_values


<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜