Magento-管理字段的默认值 [英] Magento - default value for admin field
问题描述
是否可以(通过编程或xml配置)使文本字段admin config选项具有默认值?如果可以,怎么办?
Is it possible (via programming or xml configuration) to have a default value for a text field admin config option? If so, how?
推荐答案
您可以通过模块的 config.xml 文件将默认值添加到admin config选项.通过admin config选项,我理解您的意思是配置设置选项(系统->配置).
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).
假设您具有以下 system.xml 文件. System.xml 文件是添加管理员配置选项所必需的.
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>
现在,要将默认值添加到admin配置选项中,您需要在模块的 config.xml 文件中编写以下内容.
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>
希望这会有所帮助.
有关详细说明,您可以参考:- http://alanstorm.com/magento_default_system_configuration_values
For detail explanation, you may refer to:- http://alanstorm.com/magento_default_system_configuration_values
这篇关于Magento-管理字段的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!