1

I have custom module lenses which is working well, but when I try to access data of lenses model it gives me an error. This is my code

 $Lenses= Mage::getModel('lenses/lenses');
  foreach($Lenses as $Lens)
  {
     $Lens->getData('description'); //or
     $Lens->getDescription();
  }
2

You are trying to iterate object which is not a collection. You may try following instead:

$Lenses= Mage::getModel('lenses/lenses')->getCollection();
foreach($Lenses as $Lens)
{
    $Lens->getData('description'); //or
    $Lens->getDescription();
}

If you want to access data of single object, you may do following:

$Lens = Mage::getModel('lenses/lenses')->load(12) // load by id
$Lens->getData('description'); //or
$Lens->getDescription();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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