Miha Trtnik
Miha Trtnik

Reputation: 236

magento how to call custom model

How can I call model in a custom module? Lets assume that model is really simple one and returns just arrays of static data.

I have a directory structure similar to this:

How can I include Model1.php inside controller? If I go with Mage::getModel('Mypackage/Modul/Model1) it returns error since it searches model inside Mage/Module/Model/Model1.php

Thanks!

Upvotes: 1

Views: 12752

Answers (4)

Vishal
Vishal

Reputation: 900

Hello you can try this but I have not tested it

$collection = Mage::getModel('Module/Model1')->getCollection();

Upvotes: 0

Keyur Shah
Keyur Shah

Reputation: 11533

Mage::getModel('modulename/modelname')->modelmethod();

i.e.
Mage::getModel('catalog/product')->getName();

Hope this help you

Upvotes: 1

tacheshun
tacheshun

Reputation: 61

Mage::getModel('mypackage_module/modeltest) should work. But first check your config.xml. You should have declared it like so:

          <models>
            <mypackage_module>
                <class>Mypackage_Module_Model</class>
                <resourceModel>modeltest_mysql4</resourceModel>
            </mypackage_module>
            <modeltest_mysql4>
                <class>Mypackage_Module_Model_Mysql4</class>
                <entities>
                    <modeltest>
                        <table>mypackage_module</table>
                    </modeltest>
                </entities>
            </modeltest_mysql4>
          </models>

Upvotes: 1

piCode
piCode

Reputation: 11

This should work: Mage::getModel('module/model_model1')->modelmethod();

Please note that the model folder should be "Model" not "Models"

Upvotes: 0

Related Questions