2013-02-14 62 views
2

首先,如果我在Magento白話方面犯了錯誤,這是我在該平臺上的第一個項目。本地XML覆蓋Magento擴展的默認配置

我正在爲Magento 1.7的擴展工作,它將每晚從一個FTP站點(在同一臺服務器上)導入數據。而不是硬編碼路徑的FTP目錄到我的模塊,我添加了以下到應用程序/代碼/本地/公司名稱/模塊名在/ etc/config.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <default> 
    <ftp_server_path>/home/ftpuser/</ftp_server_path> 
    </default> 
    ... other module configuration... 
</config> 

我能訪問這個存儲在我的模型中的值使用Mage::getStoreConfig('ftp_server_path')

現在我想要做的是覆蓋每個環境(我的本地機器,分段等)的ftp_server_path值。我的第一個想法是應用程序/ etc/local.xml,但我是a)不知道這是否是適當的位置和b)無法找到存儲在應用程序/ etc/local.xml中的環境特定擴展配置的一個好例子。

任何指導,你可以在這個問題提供將不勝感激。先謝謝你!

回答

3

爲什麼不能只使用system.xml文件在數據庫的後端可編輯字段中存儲此ftp路徑?

然後你只需要在每個後端改變它就可以擁有本地的/ dev/live版本。

創建你的模塊等目錄下的system.xml文件,並把這個在它:

<?xml version="1.0"?> 
<config> 
<sections> 
    <ftppath translate="label" module="yourmodule"> 
     <label>Manage </label> 
     <tab>general</tab> 
     <sort_order>50</sort_order> 
     <show_in_default>1</show_in_default> 
     <show_in_website>1</show_in_website> 
     <show_in_store>1</show_in_store> 
     <groups> 
      <general translate="label"> 
       <label>General</label> 
       <frontend_type>text</frontend_type> 
       <sort_order>10</sort_order> 
       <show_in_default>1</show_in_default> 
       <show_in_website>1</show_in_website> 
       <show_in_store>1</show_in_store> 
       <fields> 
        <path translate="label"> 
         <label>Path to FTP Server</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> 
        </path> 
       </fields> 
      </general> 
     </groups> 
    </ftppath> 
</sections> 

您可以通過執行法師:: getStoreConfig('ftppath /一般/路徑得到這個值「);

如果需要此部分僅由特定用戶羣的管理員是可見的,在adminhtml.xml文件(在模塊的etc目錄仍然)創建ACL

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
<acl> 
    <resources> 
     <admin> 
      <children> 
       <system> 
        <children> 
         <config> 
          <children> 
           <ftppath translate="title" module="yourmodule"> 
            <title>Manage FTP</title> 
            <sort_order>50</sort_order> 
           </ftppath> 
          </children> 
         </config> 
        </children> 
       </system> 
      </children> 
     </admin> 
    </resources> 
</acl> 

PS :我曾經在app/etc/local.xml文件中做過類似的工作,但是從1.7開始它不再工作了:(

+1

我很擔心,通過後臺進行此編輯會很複雜,但你的答案和[艾倫風暴的(過時)文章(間http://alanstorm.com/ custom_magento_system_configuration)我能夠得到它的工作。感謝您的幫助! – 2013-02-14 18:34:31

1

接受的SO答案中的信息雖然是一個非常好的起點,但缺乏很多需要做的事情來添加一個自定義配置文件離線在管理面板中。

即使它有些過時,@SteveGrunwell(here)在接受的答案中給出的文章有助於我使其工作。這是非常詳細的和重點。

過時的觀點似乎是從版本1.4開始,ACL部分假設位於模塊的/ etc /文件夾中的adminhtml.xml文件中。

另一個鏈接,幫助我在magento site