0
votes

I have created a custom module using Magento's developer guide but the installer script is not working. I get this error:

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

My 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>

this is installer script

<?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();

My directory structure is

1
You need to read How to Ask. If you've written the installer script then please show us the code. If the custom module has failed because of its code then please show us that. - Enigmativity
This is not suitable on Stack Overflow - possibly on magento.stackexchange.com but make sure to check their "How to ask" first. - Pekka

1 Answers

1
votes

Fatal error: Class 'Mdg_Giftregistry_Model_Resource_Setup' not found

This is because you're referencing a custom setup class in your config.xml:

<setup>
    <module>Mdg_Giftregistry</module>
    <class>Mdg_Giftregistry_Model_Resource_Setup</class>
</setup>

I assume that you haven't created the class yet, so you have two options:

  1. Create the class Mdg_Giftregistry_Model_Resource_Setup which would extend Mage_Core_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. Change your config.xml entry so it uses the core class:

    <class>Mage_Core_Model_Resource_Setup</class>
    

You are likely to still have more problems with your installers, but without sharing your code it's hard to know/predict.

Good luck!