How do I get data from my custom module table?
Question
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.
Solution
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());
}
OTHER TIPS
Try doing
$date = Mage::getModel('namespace_modulename/tablename')->load($id);
print_r($date->getData('date_to'));
where $id is the primary key.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange