Hello,
I am trying to retrieve data from a MYSQL table but I am getting the following error:
Code:
Warning: Invalid argument supplied for foreach() in C:\wamp\www\zendpro\application\views\indexIndex.php on line 16
I did the followings:
in the index.php file, I inserted the following. I have an .ini file which holds the database connection settings.
Code:
// setup database
$db = Zend_Db::factory($config_db->db->adapter, $config_db->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('db', $db);
In the model folder, I defined a class called album as follow:
Code:
<?php
class Album extends Zend_Db_Table {
protected $_name = 'album';
}
?>
In the IndexController.php, I inserted the following:
Code:
Zend_Loader::loadClass('Album');
$album = new Album();
$this->view->albums = $album->fetchAll();
In the indexIndex.php, I inserted the following code:
Code:
<?php foreach($this->view->albums as $album) : ?>
<tr>
<td><?php echo $this->escape($album->title);?></td>
<td><?php echo $this->escape($album->artist);?></td>
<td>
<a href="<?php echo $this->baseUrl; ?>/index/modify/id/<?php
echo $album->id;?>">Modifier</a>
<a href="<?php echo $this->baseUrl; ?>/index/delete/id/<?php
echo $album->id;?>">Supprimer</a>
</td>
</tr>
<?php endforeach; ?>
It's just not displaying the right thing and I have been trying to solve this for the past days. The foreach statement in the indexIndex.php file is not happy at all.
I would appreciate if anyone could kindly help me.
Regards