With the Paginator in the trunk it is now possible to register a
filter(-chain). I've written one filter for using a callback method
with Zend_Paginator, which is Zend_Filter_Callback. This allows you to
use Paginator with the Db(Table)Select adapter and pass the rows to a
factory method so you can construct your domain models from them.
These models are then encapsulated by Zend_Paginator so you can keep
all the Paginator goodies in addition to your domain models.
$paginator = new Zend_Paginator(new
Zend_Paginator_Adapter_DbTableSelect($select));
$paginator->setCurrentPageNumber($page)
->setItemCountPerPage($perPage)
->setFilter(new Zend_Filter_Callback(array($this,
'getZebrasByRowset'))); // Use in the same way as call_user_func
public function getZebrasByRowset(Zend_Db_Table_Rowset_Abstract $rowset)
{
$zebras = array();
foreach ($rowset as $row) {
$zebras[] = new Zebra(); // And don't forget to populate your
Zebra object with data from the row
}
return $zebras;
}
Your controller action would look something like this:
public function listAction()
{
$zoo = new Zoo();
$zebras = $zoo->getZebras(); // This will be a Paginator with
Zebra models
$this->view->zebras = $zebras;
}
Hopefully this helps : )
Cheers,
- Jurriën
On Mar 23, 2009, at 08:55 , keith Pope wrote:
I use the paginator within my Model, my model will then either return
a rowset or a paginator object. I see the paginator as a domain
service and therefore reasonable for my Model to return, its not
prefect but saves having to write your own model aware paginator
adapter.
2009/3/22 Marko Korhonen <marko.korho...@datafisher.com>:
hi,
I try to figure out how should I make my controller,model and
paginator
stuff so it makes sense.
Let's make a simple example:
I want to get list of stuff from Model and throw it to my Paginator:
public function listAction()
{
$model = new Zebra();
// Get 10 zebras at the time and paginate
$zebras = $model->getSlowZebrasSoICanEatThem(10, $this-
>_getParam("page",
1));
// OK, should Model return rowset, select object or paginator ???
// if it's paginator, I can send it to view
$this->view->paginator = $zebras;
// if it's select object, I must declare my Paginator and set
select
object for it
...set paginator...
// If it's rowset... ehm, what I can do with it? can Paginator eat
rowset?
}
--
View this message in context:
http://www.nabble.com/Controller%2C-Model-and-Paginator%2C-and-I-want-my-Girls..-ehh%2C-Controllers-thin-tp22645201p22645201.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------