I have a function abc in model . i want to call that function abc in controller.
i am new to magento and dnt have any idea regarding this. Can any body tell me how to do this
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
It's called Magic Function.
$yourModel = Mage::getModel('yourmodulename/yourmodelname')->load($id); $return = $yourModel->abc();
or you can do
$yourModel = Mage::getSingleton('yourmodulename/yourmodelname')->load($id); $return = $yourModel->abc();
this is for your reference of getSingleton VS getModel
Suppose your configuration is -
<models> <modulename> <!-- this here is the first part of your getModel() call --> <class>Packagename_Modulename_Model</class> <resourceModel>modulename_mysql4</resourceModel> </modulename> <modulename_mysql4> <class>Packagename_Modulename_Model_Mysql4</class> <entities> <abc> <table>table_abc</table> </abc> </entities> </modulename_mysql4> </models>
Now you need the second part after the
/. If your model name is:
Packagename_Modulename_Model_Abc, then you take everything after your prefix, which was defined in the config
Packagename_Modulename_Model, lowercase the first character
Now you can access your model following way: