6

I have a custom module with its own table which saves the date inside the column named date_to.

I am trying to access the values from only this column but when I load the collection and call getData('date_to') I get the whole collection and not just the date_to column.

Here is what I have tried so far:

$date = Mage::getModel('namespace_modulename/tablename')->getData('date_to');

print_r($date);

When I do print_r($date); I get the whole collection even though I have specified in parenthesis the I only want the date_to column values.

I know I'm missing out an important piece and would like for some help please.

6
  • try getDateTo() like Mage::getModel('namespace_modulename/tablename')->getDateTo() Commented May 28, 2015 at 17:08
  • @TimHallman thaks for your input, I get null returned when I use getDateTo() even though there are values in that colum... Commented May 28, 2015 at 17:17
  • @TimHallman yes, I get an error Call to undefined method Namespace_Module_Model_Resource_Custom_Data_Collection::getDateTo() Commented May 28, 2015 at 17:32
  • So when you do echo '<pre>';print_r($date);echo '</pre>'; do you see the date_to object or method? Commented May 28, 2015 at 17:38
  • @TimHallman Yes I get the object, namespace_modulename/tablename [_resourceModel:protected] => date_to [_resource:protected] Commented May 28, 2015 at 18:33

2 Answers 2

6

Thanks for the help, I had to loop over the collection like below:

$date = Mage::getModel('namespace_modulename/tablename');

$collection = $date->getCollection();
foreach($collection as $date_to){
    print_r($date_to->getData());
    print_r($date_to->getDateTo());
}
1
  • can i write this code on controller file Commented Jan 11, 2017 at 12:34
1

Try doing

$date = Mage::getModel('namespace_modulename/tablename')->load($id);

print_r($date->getData('date_to'));

where $id is the primary key.

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.