WHAT'S HOT
Prev | Current Page 370 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

com>
Zend Framework in Action (Ch01) Manning Publications Co. 57
1 Iterator??™s current() returns current item
B return null at the end to break out of a foreach() or while()
2 Iterator??™s key() returns a point to the current item
3 Iterator??™s next() moves the pointer forward by one item
4 Iterator??™s rewind() resets the pointer to the start
5 Iterator??™s valid() checks that the pointer is valid
Zend_Db_Table_Rowset_Abstract holds its data in an array called _rows and holds the count of how
many items are in the array in _count. We also need to keep track of where we are in the array as the foreach()
is progressing and the _pointer member variable is used for this. To implement Iterator, a class needs to
provide 5 functions, current(), key(), next(), rewind() and valid(). These functions are very simple as you can
see in listing 17.12 as they simply manipulate the _pointer variable as required and return the correct data in
current().
One limitation of Iterator is that it is forward traversal of the data and does not allow for random access of
the data. That is, you cannot do:
$aUser = $userRowset[4];
with an instance of Zend_Db_Table_Rowset_Abstract. This is by design as the underlying technology
behind the class is a database that may not allow random access to a dataset.


Pages:
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
pustaki szklane House Extension Kąty Rybackie noclegi kasyno Kołobrzeg