I want to make use of Magic Methods in my Custom Module.
I created a new Model with different member variables (variable1, variable2) and I want to get them like getVariable1.
How do I need to declare those member variables? Can I set them on private? What else am I missing?
Somewhere I read I need to save them in $_data['variable1']
, but that doesn't work.
Thanks!
Best Answer
Magic methods are implemented via
Varien_Object
class.You'll need to either extend that class or any other class which extends from
Varien_Object
likeMage_Core_Model_Abstract
for example. You are not required to define any variables or methods in your model as long as your method starts withget
,set
,uns
andhas
, that is assuming you want them to work as magic methods.So you can write something like this:
If you do
Zend_Debug::dump($model);
you'll notice that your data is stored in_data
property which is declared inVarien_Object
class.Example: