magento

Model

Load model

You can load Magento model using the following code: Mage::getModel(‘modulename/modelname’)

Example: Mage::getModel(‘catalog/product’) This will load Mage_Catalog_Model_product

Create an empty model

To create a new model in your module Add a folder Model in your module root folder and create a file Modelname.php in this folder. for example Rick/Demo/Model/Modelname.php

The class name of your model does matter call it like this:

<?php
class Rick_Demo_Model_Modelname {

}

make sure your model is defined in your config.xml in the etc folder of your module

Here an example:

2.0.4 Rick_Demo_Model

To load your module use the following code:

Mage::getModel('customemodelname/modelname')

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow