2011-05-01 139 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>