WHAT'S HOT
Prev | Current Page 369 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

This can be seen within the Zend Framework in the Zend_Db_Table_Rowset_Abstract class and is
used to allow traversal over all the results returned from a quiery. Let??™s look at some highlights of the
implementation. Firstly, we use Zend_Db_Table_Rowset as shown in listing 17.11.
Listing 17.11 Using iteration with Zend_Db_Table_Rowset
class Users extends Zend_Db_Table {} A
$users = new Users();
$userRowset = $users->fetchAll(); B
foreach ($userRowset as $user) { C
echo $user->name . "\n";
}
A Gateway to the Users database table
B Get Rowset
C Iterator over the Rowset class
As we expect, using a Rowset is as easy as using an array. This is made possible because
Zend_Db_Table_Rowset_Abstract implements the Iterator SPL interface as shown in listing 17.12.
Listing 17.12 Iterator implementation within Zend_Db_Table_Rowset_Abstract
abstract class Zend_Db_Table_Rowset_Abstract implements Iterator, Countable
{
protected $_rows = array(); A
public function current() 1
{
if ($this->valid() === false) {
return null; B
}
return $this->_rows[$this->_pointer];
}
public function key() 2
{
return $this->_pointer;
}
public function next() 3
{
++$this->_pointer;
}
public function rewind() 4
{
$this->_pointer = 0;
}
public function valid() 5
{
return $this->_pointer < $this->_count;
}
}
A Private array of Rows created by select function
Licensed to Menshu You

Pages:
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
prezenty hale ABC biuro rachunkowe gdańsk Teksty piosenek