MGP
MGP

Reputation: 653

Magento Model not loading

I'm trying to create a simple module to magento. I've created my controller, my routings but for some reason I can't get access to my model. As far as I know, it's not even loaded.

I get no error message, and the model object isn't created.

What might be causing this?

Here's some information:

Controller:

class MyVendor_MyModule_IndexController extends Mage_Core_Controller_Front_Action
{

    public function pingAction(){

        $model = Mage::getModel('mymodule/mymodule');       
        echo "<pre>" . print_r($model->load(1),true);

    }
}

Model tree view:

MyVendor
-MyModule
-- controllers
---- IndexController.php
-- Model
---- Mysql4
-------- MyModule.php
-------- MyModule
---------------- Collection.php
---- MyModule.php
-- etc
---- config.xml

config.xml

<?xml version="1.0" encoding="UTF-8"?>

<config> 
    <modules>
        <MyVendor_MyModule>
            <version>0.0.1</version>
        </MyVendor_MyModule>
    </modules>
    <frontend>
        <routers>
            <mymodule>
                <use>standard</use>
                <args>
                    <module>MyVendor_MyModule</module>
                    <frontName>mymodule</frontName>
                </args>
            </mymodule>
        </routers>   
    </frontend>
    <global>
        <models>
            <mymodule>
                <class>MyVendor_MyModule_Model</class>
                <resourceModel>mymodule_mysql4</resourceModel>
            </mymodule>
            <mymodule_mysql4>
                <class>MyVendor_MyModule_Model_Mysql4</class>
                <entities>
                    <mymodule>
                        <table>mymodule_table</table>
                    </mymodule>
                </entities>
            </mymodule_mysql4>
        </models>
        <resources>
                    <mymodule_setup>
                        <setup>
                                <module>MyVendor_MyModule</module>
                        </setup>
                        <connection>
                                <use>core_setup</use>
                        </connection>
                    </mymodule_setup>
                    <mymodule_setup>
                        <connection>
                                <use>core_write</use>
                        </connection>
                    </mymodule_setup>
                    <mymodule_setup>
                        <connection>
                                <use>core_read</use>
                        </connection>
                    </mymodule_setup>
            </resources>
    </global>
</config>

And in my Model I've got a simple:

class MyVendor_MyModule_Model_Mysql4_MyModule extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {   
        $this->_init('mymodule/mymodule', 'id');
    }
}

Upvotes: 1

Views: 5137

Answers (2)

Oscprofessionals
Oscprofessionals

Reputation: 2174

Did you add in app/etc/modules/MyVendor_MyModule.xml and are you sure there are no typo errors for that. If you find your module in admin then that confirms your module is registered.

You are extending a controller.So what was done to override core controller.

Upvotes: 0

Jared Kipe
Jared Kipe

Reputation: 1187

Depending on platform, Mage::getModel('mymodule/mymodule'); may be case sensitive when looking for the file to load (namely that it should be Mage::getModel('myModule/myModule'); given your folder structure and naming)

Check what get_class(Mage::getModel('mymodule/mymodule')) returns. Is it the classname of your class? If not then you're not even making an instance of your object. Check the camel-casing earlier, and that you actually have a file /MyVendor/MyModule/Model/MyModule.php (which you didn't include the code from).

If you have an instance of you class, you probably don't have any rows in the DB to support it. So ->load(1); isn't going to do anything.

Upvotes: 5

Related Questions