在Magento PHP脚本中定义$ this变量

时间:2016-02-18 15:46:30

标签: php magento this

我有一个不可更改的脚本,但不起作用。但是可以在开头或结尾添加代码。

这是剧本:

$installer = $this;
$installer->startSetup();

$installer->setConfigData('general/country/default', 'DE');
$installer->setConfigData('general/country/allow','BE,BG,DK,DE,CY');
$installer->setConfigData('general/country/optional_zip_countries','IE');
$installer->setConfigData('general/country/eu_countries','BE,CY');

$installer->endSetup();

如果我将脚本的开头更改为:

$installer = $this;
$installer = Mage::getModel("eav/entity_setup", "core_setup");
$installer->startSetup();

它会起作用,但正如我所说,不可能在脚本中写入。我收到的错误是:

Fatal error: Call to a member function startSetup() on a non-object

有没有办法让该脚本有效?

这是一个用于导入系统配置的Magento脚本。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在模块的$this中定义要由设置(又名config.xml)使用的类,如下所示:

<?xml version="1.0"?>
<config>
    <global>
        <!--other definitions-->
        <resources>
            <namespace_module_setup>
                <setup>
                    <module>Namespace_Module</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
            </namespace_module_setup>
        </resources>
        <!--other definitions-->
    </global>
    <!--other definitions-->
</config>