0

I am trying to create a model for the first time in Magento - the resource model is Mygroup_Mymodule_Model_Resource_Link

The model alias I have used is mygroup_mymodule/link

I am trying to call $myVar = Mage::getModel('mygroup_mymodule/link') but I am getting this error:

Warning: include(Mage/Mygroup/Mymodule/Resource/Model/Link.php): failed to open stream: No such file or directory in /[root]/lib/Varien/Autoload.php on line 93

This is true: there is no file there, or in app/code/local/Mygroup/Mymodule/Resource/Model/Link.php, but I don't know why Magento thinks there should be.

My folder structure is:

...
- Model/
    - Link.php
    - Resource/
        - Link.php
        - Link/
            - Collection.php
...

app/code/local/Mygroup/Mymodule/etc/config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Mygroup_Mymodule>
            <version>0.0.6</version>
        </Mygroup_Mymodule>
    </modules>

    <frontend>
        <routers>
            <downloadable>
                <use>standard</use>
                <args>
                    <modules>
                        <Mygroup_Mymodule before="Mage_Downloadable">Mygroup_Mymodule</Mygroup_Mymodule>
                    </modules>
                </args>
            </downloadable>
        </routers>
    </frontend>

    <global>
        <helpers>
            <downloadable>
                <rewrite>
                    <download>Mygroup_Mymodule_Helper_Download</download>
                </rewrite>
            </downloadable>
        </helpers>

        <models>

            <mygroup_mymodule>

                <class>Mygroup_Mymodule_Model</class>

                <resourceModel>mygroup_mymodule_resource</resourceModel>

            </mygroup_mymodule>

            <mygroup_mymodule_resource>

                <entities>

                    <link>

                        <table>mygroup_mymodule_link</table>

                    </link>

                </entities>

            </mygroup_mymodule_resource>

        </models>

        <resources>

            <mygroup_mymodule_setup>

                <setup>

                    <module>Mygroup_Mymodule</module>

                    <class>Mage_Core_Model_Resource_Setup</class>

                </setup>

                <connection>
                    <use>core_setup</use>
                </connection>

            </mygroup_mymodule_setup>

        </resources>


    </global>
</config>

app/code/local/Mygroup/Mymodule/Model/Link.php:

<?php
class Mygroup_Mymodule_Model_Link extends Mage_Core_Model_Abstract
{

    protected function _construct()
    {
        $this->_init('mygroup_mymodule/link');
    }
    ...

app/code/local/Mygroup/Mymodule/Model/Resource/Link.php:

<?php
class Mygroup_Mymodule_Model_Resource_Link
    extends Mage_Core_Model_Resource_Db_Abstract
{
    protected function _construct()
    {
        $this->_init('mygroup_mymodule/link', 'entity_id');
    }
}

app/code/local/Mygroup/Mymodule/Model/Resource/Link/Collection.php:

<?php
class Mygroup_Mymodule_Model_Resource_Link_Collection
    extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
    protected function _construct()
    {
        parent::_construct();

        $this->_init(
            'mygroup_mymodule/link',
            'mygroup_mymodule/link'
        );
    }
}

I also have a Helper and a controller in the module (as you can see in the config file), but I don't think that's relevant here.

Thanks very much for any help!

I am using CE 1.9.0.1

1

It looks as if you're missing a class definition in your resource model config:

        <mygroup_mymodule_resource>
            <class>Mygroup_Mymodule_Model_Resource</class>
            <entities>
                <link>
                    <table>mygroup_mymodule_link</table>
                </link>
            </entities>
        </mygroup_mymodule_resource>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.