Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-04-2008, 09:16 PM
Junior Member
 
Join Date: Mar 2008
Posts: 2
Default problem with Zend_Db_Table

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-05-2008, 03:29 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

In IndexController.php, where is your action method?
You need something like this to put your code in:

Code:
function indexAction()
{
     $album = new Album();
     $this->view->albums = $album->fetchAll();
     // ...
}
What is indexIndex.php?

If that is your view file, it should be index.phtml and stored in an index folder inside of your views directory.

Hope this helps!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-08-2008, 09:15 PM
Junior Member
 
Join Date: Mar 2008
Posts: 2
Default

Thanks xentek.

I did the necessary changes. My mistake was that I called $this->render before the code $this->view->albums = $album->fetchAll();. I changed the position and it now worked perfectly.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:05 AM.