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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-21-2008, 02:46 PM
tru tru is offline
Junior Member
 
Join Date: Jul 2008
Posts: 10
Default Zend_Db_Table results problem

As I'm new, hello to every user of this forum!

This is my code
(controller)
PHP Code:
public function indexAction()
{
    
$table = new Users();
        
    
$rows $table->getAllUsers();
}
class 
Users extends Zend_Db_Table_Abstract
{
    protected 
$_name 'users';
    protected 
$_primary 'id';
    
    public function 
getAllUsers() {
        return 
$this->fetchAll()->toArray();
    }

(view)
PHP Code:
<table border="1">  
    <tr>  
      <th>ID</th>  
      <th>Login</th>        
      <th>Password</th>       
      <th>E-mail</th>        
      <th>Action</th>       
    </tr>  
  <?php $rows $this->rows
  foreach (
$rows as $key => $user) { ?>  
    <tr>  
      <td><?=$user['id']?></td>      
      <td><?=$user['login']?></td>  
      <td><?=$user['password']?></td>        
      <td><?=$user['email']?></td>     
      <td>  
        <a href="edit/id/<?=$user['id']?>">Edit</a>  
        |  
        <a href="del/id/<?=$user['id']?>">Delete</a>         
      </td>     
    </tr>   
  <? ?>  
</table>
When I run the script the following error occures
Code:
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\zend\application\views\scripts\user\index.phtml on line 21
What's wrong with my script?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-22-2008, 01:00 AM
Member
 
Join Date: Jul 2008
Posts: 60
Default

You're not assigning the $rows variable to the view. In the controller you need to do.
Code:
$this->view->rows = $table->getAllUsers();
at the moment you're only assigning it to a local variable.
__________________
Brenton Alker
Brisbane, Australia

http://blog.tekerson.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-22-2008, 11:23 AM
tru tru is offline
Junior Member
 
Join Date: Jul 2008
Posts: 10
Default

Jesus Christ, you're awesome!
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 01:00 AM.