Magento 安装程序脚本无法运行 1.9

Magento installer script not working 1.9

我使用 Magento 的开发人员指南创建了一个自定义模块,但安装程序脚本无法正常工作。我收到此错误:

Fatal error: Class 'Mdg_Giftregistry_Model_Resource_Setup' not found in C:\xampp\htdocs\magento\includes\src\Mage_Core_Model_Resource_Setup.php on line 234

directory structure

我的config.xml:

    <?xml version="1.0"?>
<config>
    <modules>
        <Mdg_Giftregistry>
            <version>0.1.0</version>
        </Mdg_Giftregistry>
    </modules>
    <frontend>
        <routers>
            <mdg_giftregistry>
                <use>standard</use>
                <args>
                    <module>Mdg_Giftregistry</module>
                    <frontName>giftregistry</frontName>
                </args>
            </mdg_giftregistry>
        </routers>
    </frontend>
    <global>
        <models>
            <mdg_giftregistry>
                <class>Mdg_Giftregistry_Model</class>
                <resourceModel>mdg_giftregistry_mysql4</resourceModel>
            </mdg_giftregistry>
            <mdg_giftregistry_mysql4>
                <class>Mdg_Giftregistry_Model_Mysql4</class>
                <entities>
                    <entity>
                        <table>mdg_giftregistry_entity</table>
                    </entity>
                    <item>
                        <table>mdg_giftregistry_item</table>
                    </item>
                    <type>
                        <table>mdg_giftregistry_type</table>
                    </type>
                </entities>
            </mdg_giftregistry_mysql4>
        </models>
        <resources>
            <mdg_giftregistry_setup>
                <setup>
                    <module>Mdg_Giftregistry</module>
                    <class>Mage_Core_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mdg_giftregistry_setup>
            <mdg_giftregistry_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </mdg_giftregistry_write>
            <mdg_giftregistry_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mdg_giftregistry_read>
        </resources>
        <blocks>
            <mdg_giftregistry>
                <class>Mdg_Giftregistry_Block</class>
            </mdg_giftregistry>
        </blocks>
        <helpers>
            <mdg_giftregistry>
                <class>Mdg_Giftregistry_Helper</class>
            </mdg_giftregistry>
        </helpers>

    </global>
</config>

这是安装脚本

<?php
$installer = $this;
$installer->startSetup();
// Create the mdg_giftregistry/registry table
$tableName = $installer->getTable('mdg_giftregistry/entity');
// Check if the table already exists
if ($installer->getConnection()->isTableExists($tableName) != true) {
$table = $installer->getConnection()->newTable($tableName)->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER,
null,
array(
'identity' => true,
'unsigned' => true,
'nullable' => false,
'primary' => true,
),
'Entity Id'
)
->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER,
null,
array(
'unsigned' => true,
'nullable' => false,
'default' => '0',
),
'Customer Id'
)
->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT,
null,
array(
'unsigned' => true,
'nullable' => false,
'default' => '0',
),
'Type Id')
->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT,
null,
array(
'unsigned' => true,
'nullable' => false,
'default' => '0',
),
'Website Id'
)
->addColumn('event_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255,
array(),
'Event Name'
)
->addColumn('event_date', Varien_Db_Ddl_Table::TYPE_DATE,
null,
array(),
'Event Date'
)->addColumn('event_country', Varien_Db_Ddl_Table::TYPE_TEXT,
3,
array(),
'Event Country'
)
->addColumn('event_location', Varien_Db_Ddl_Table::TYPE_TEXT,
255,array(),
'Event Location'
)
->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
null,
array(
'nullable' => false,
),
'Created At')
->addIndex($installer->getIdxName('mdg_giftregistry/entity',
array('customer_id')),
array('customer_id'))
->addIndex($installer->getIdxName('mdg_giftregistry/entity',
array('website_id')),
array('website_id'))
->addIndex($installer->getIdxName('mdg_giftregistry/entity',
array('type_id')),
array('type_id'))
->addForeignKey(
$installer->getFkName(
'mdg_giftregistry/entity',
'customer_id',
'customer/entity','entity_id'
),
'customer_id', $installer->getTable('customer/entity'),
'entity_id',
Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->addForeignKey(
$installer->getFkName(
'mdg_giftregistry/entity',
'website_id',
'core/website',
'website_id'
),
'website_id', $installer->getTable('core/website'),
'website_id',
Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->addForeignKey(
$installer->getFkName('mdg_giftregistry/entity',
'type_id',
'mdg_giftregistry/type',
'type_id'
),
'type_id', $installer->getTable('mdg_giftregistry/type'),
'type_id',
Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE);
$installer->getConnection()->createTable($table);
}
$installer->endSetup();

我的目录结构是

Fatal error: Class 'Mdg_Giftregistry_Model_Resource_Setup' not found

这是因为您在 config.xml:

中引用了自定义设置 class
<setup>
    <module>Mdg_Giftregistry</module>
    <class>Mdg_Giftregistry_Model_Resource_Setup</class>
</setup>

我假设您还没有创建 class,所以您有两个选择:

  1. 创建将扩展 Mage_Core_Model_Resource_Setup:

    的 class Mdg_Giftregistry_Model_Resource_Setup
    # File: app/code/local/Mdg/Giftregistry/Model/Resource/Setup.php
    class Mdg_Giftregistry_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
    {
    
    }
    
  2. 更改您的 config.xml 条目,使其使用核心 class:

    <class>Mage_Core_Model_Resource_Setup</class>
    

您的安装程序可能还有更多问题,但如果不共享您的代码,就很难 know/predict。

祝你好运!