I have created a custom module with my own db table. My question is; what data is available to me in the block class while I'm editing an entry?

For example, I use the products collection in my block and call it as follows:

$collection = Mage::getModel('catalog/product')

Now, I can use the getters to retrieve info, such as:

... etc, etc

All good. Now, if my custom model is called test_model/test, and I have an instance like so:

$test = Mage::getModel('test_model/test');

Calling a getter for getMyfield(); produces nothing. Obviously, if I explicitly load an item:

$test = Mage::getModel('test_model/test')->load('1');

Then I do have those getters available.

So... what am I missing? Why do I have to load the row I want first? Shouldn't it be available on edit with $this->getMyfield();.

Help a Mage nooby out, please.

1 Answer 1


If you use Mage::getModel('some/model') method Magento only returns model class without values.
If you use Mage::getModel('some/model')->load($id) then Magento loads the object (one row) from db table and returns this object with it's values. And you can get some value via $model->getMyField(). Also you can define some methods and default values for model class:

class My_SomeModule_Model_SomeModel extends Mage_Core_Model_Abstract{
    protected function _construct()
    public function getSomeValue(){
        //here is your some logic to calculate or load some $value
        return $value; 
    public function validate(){
        //you can write object values validation logic  
        return $this->getMyField()!==null;
    protected function _beforeSave(){
           throw new Exception('Some validation Message here');
        return parent::_beforeSave();

Using model:

$model->setAnotherField('some value');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.