[Solar-talk] Pager helper changes
Rodrigo Moraes
rodrigo.moraes at gmail.com
Sat Jun 30 08:55:07 CDT 2007
Hi,
Happy to see that Paul may consider the pager helper to inclusion in
Solar (saw a note on the todo list), or even a very adapted version of
it, I've done a big refactoring on the pager family and included a new
adapter (which makes GMail-like pagination). This inevitably breaks
previous usage in favor of a cleaner and more flexible way (I hope).
Now the pager is called passing just two optional parameters:
$pager = $this->pager('count', $config);
The first one is the adapter name (available: 'sliding' (default),
'jumping', 'simple' and the new one, 'count'); the second is the
adapter config, and it returns a configured adapter. The decorator
name is defined in the config key 'decorator' and its configuration is
defined in the config key 'display', althought the defaults are ready
for most common usages, I think.
Then on fetch the pager info is passed to the adapter. Putting
everything together and using the default adapter:
echo $this->pager()->fetch($href, $page, $paging, $count);
Observe that the number of pages is no longer passed to the helper. It
now receives paging (items per page) and count (number of items to be
paginated) and calculates the number of pages based on this. This is
because some adapters may need to know about paging and items count,
while number of pages can be calculated with this two values.
The new adapter, 'count', uses the new info to generate GMail-like
pagination. An example of the output:
« Newest ‹ Newer 101-150 of 2010 Older › Oldest »
That's it. In the middle of the refactoring I found two not very
important bugs that were present in the old pager (param not being
used in a method; wrong locale key called in another), and in the end
I think the API is cleaner (less parameters) and the code is smaller
and more flexible for adapters.
Let me know if you have problems or doubts. :)
-- rodrigo
More information about the Solar-talk
mailing list