View Single Post
  #10 (permalink)  
Old 05-26-2008, 02:31 PM
Filip Filip is offline
Junior Member
 
Join Date: Apr 2008
Posts: 28
Default

Fetching data from your table.

Either you write a function in your table class (the class Bugs in the example) or you use a predefined method (such as $table->find(<primary key value to look for>) )

Predefined method:

Code:
<?

 $bugs = new Bugs();
 $bugs = $bugs->fetchAll();
 
//$bugs now contains the complete table Bugs
or
Code:
$bugs = new Bugs();
       $bugs = $bugs->find('1')->current();

// this will return a zend_table_row with id 1 (if it exists)
if you write a new function in your bugs class

Code:
private function getUserBugs($userID)
{
    $sql = $this->select()->where('<column> = ?', $userID)
                                 ->where(<other where statements>)
                                 -> order(.....)
                                 ->limitpage(.....)
    return $this->fetchAll($sql)
}
now you can use this in your function layer (where your business logic should be)


Code:
$bugs = new bugs();

   $bugs = $bugs->getUserBugs('1');
after which $bugs will contain a rowset of 0 - X rows.

Iterating between them is nice & easy with a foreach.


and last & not least. If you set the referencemap & the dependentTables like I said in my previous post, there's no need to use joins in your syntax. You can just as easily use the method findparentRow // findDependentRowset

(see more in Zend Documentation on the 2 methods...)

Last edited by Filip : 05-26-2008 at 02:33 PM. Reason: code tags
Reply With Quote