<h4><?php echo $this->__('Module List') ?></h4>
<?php
/*
This will load one record from your database table.
load(<module>_id) will load whatever ID number you give it.
*/
/**/
$news = Mage::getModel('news/news')->load(1);
echo $news->getNewsId();
echo $news->getTitle();
echo $news->getContent();
echo $news->getStatus();
/*
This block of code loads all of the records in the database table.
It will iterate through the collection and the first thing it will do
is set the Title to the current value of $i which is incremented each
iteration and then echo that value back out. At the very end it will
save the entire collection.
*/
/**/
$i = 0;
$collection = Mage::getModel('news/news')->getCollection();
// print_r($collection);
$collection->setPageSize(5);
$collection->setCurPage(2);
$size = $collection->getSize();
$cnt = count($collection);
foreach ($collection as $item) {
$i = $i+1;
$item->setTitle($i);
echo $item->getTitle();echo '<br/>';
}
$collection->walk('save');
/*
This shows how to load one value, change something and save it.
*/
/**/
$object = Mage::getModel('news/news')->load(1);
$object->setTitle('This is a changed title');
$object->save();
?>