Friday, April 20, 2012

Call Custom Model method/function

For example,I have created a custom module UserProfile .
i.e
magento\app\code\local\CustomerProfile\Userprofile

and my model in Userprofile is
magento\app\code\local\CustomerProfile\Userprofile\Model\Customersettings.php

Customersettings.php is as following:


class CustomerProfile_Userprofile_Model_Customersettings extends Mage_Core_Model_Abstract
{

protected function _construct()
{
$this->_init("userprofile/customersettings");
}

function getmessage()
       {
              echo "Hello From Custom model method:";
       }
}


I can call the method of custom model anywhere as following:

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

i.e.
Mage::getModel('userprofile/customersettings')->getmessage();

1 comment:

  1. Great blog. All posts have something to learn. Your work is very good and i appreciate you and hoping for some more informative posts.keep writing
    magento development company in bangalore 

    ReplyDelete

Fatal error: Class Zend\Stdlib\Parameters contains 1 abstract method... magento 2

Fatal error: Class Zend\Stdlib\Parameters contains 1 abstract method and must therefore be declared abstract or implement the remaining met...