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();
  }
0

1 Answer 1

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();
0

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.