本地XML覆盖Magento扩展的默认配置

时间:2013-02-14 16:15:00

标签: magento configuration

首先,如果我对Magento白话有任何错误,请原谅,这是我在平台上的第一个项目。

我正在研究Magento 1.7的扩展程序,它将在每晚从FTP站点(在同一台服务器上)导入数据。我没有将FTP目录的路径硬编码到我的模块中,而是将以下内容添加到app / code / local / CompanyName / ModuleName / 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值。我的第一个想法是app / etc / local.xml,但我是a)不确定这是否是合适的位置,并且b)无法找到存储在app / etc / local.xml中的特定于环境的扩展配置的好例子。

我们非常感谢您就此事提供的任何指导。提前谢谢!

2 个答案:

答案 0 :(得分:3)

为什么不能只使用system.xml文件在后端的可编辑字段中将此ftp路径存储在数据库中?

然后你只需要在每个后端更改它以拥有本地/ dev / live版本。

在模块的etc目录中创建一个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>

你可以通过做Mage :: getStoreConfig('ftppath / general / path')获得这个值;

如果您需要此部分仅由特定用户组的管理员查看,请在adminhtml.xml文件中创建acl(仍在模块的etc目录中)

<?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 :(得分:1)

接受的SO答案中的信息虽然是一个非常好的起点,但缺少在管理面板中添加自定义配置部分需要做的很多事情。

即使它有点过时,@SteveGrunwell(here)在接受的答案中提供的文章对我的工作起到了重要作用。它非常详细而且非常重要。

过时的观点似乎是从版本1.4及更高版本开始,ACL部分应该存在于模块的/ etc /文件夹中的adminhtml.xml文件中。

帮助我magento site

的另一个链接
相关问题