2011-05-01 134 views

回答

32

您可以通过您的模块的config.xml文件将默认值添加到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> 

现在,默认值添加到管理员的配置选项,你需要写在你的模块的config.xml文件以下。

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

希望这会有所帮助。

对于详细的解释,你可以参考: - http://alanstorm.com/magento_default_system_configuration_values

+0

这似乎并不为我工作。我刷新了缓存,存储缓存,登录和注销,清除了浏览器缓存。我还必须做些什么才能使违约行为起作用? – ahnbizcad 2015-10-07 21:11:16

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