2013-02-14 31 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