Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

get and set methods
 
R.Verheij
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-04-08
Amsterdam, Netherlands
 

Hi,

My question is: How do functions like setSomething(), getSomething() and unsSomething() work, while they are not defined anywhere?
I’m customising the iDEAL payment module to create my own. Everything is going fine, but for the purpose of documentation I’d like to know how this works:
In the controller (extending Mage_Core_Controller_Front_Action) there is a function:

public function failureAction ()
{
  
...
  
$session Mage::getSingleton('checkout/session');
  ...
  
$session->setSomeErrorMessage($this->__('Some error message'));
}

And in the block file Failure.php ( extending Mage_Core_Block_Template) there is a function:

public function getErrorMessage ()
{
  $error 
Mage::getSingleton('checkout/session')->getSomeErrorMessage();
  
Mage::getSingleton('checkout/session')->unsSomeErrorMessage();
  return 
$error;
}

which is called upon in the template failure.phtml… And it works! The error message is saved and passed to the template, but how?  gulp Nowhere, not in any file, a function setSomeErrorMessage is defined.

So I’m guessing this is aranged in the Zend Framework? Or the Varien Framework?
And is there any reason the functions are called on the checkout/session class? Or could it be any class?

 
Magento Community Magento Community
Magento Community
Magento Community
 
laurent
Member
 
Total Posts:  75
Joined:  2007-08-31
Paris, France
 

Almost all classes extend Varien_Object wich have the magic method __call.
@see Method overloading in PHP doc

 
Magento Community Magento Community
Magento Community
Magento Community
 
R.Verheij
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-04-08
Amsterdam, Netherlands
 

Tnx, thats what I was looking for!  smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top