Pagination in Views
It's up to you to decide how to show records to the user, but most often this will be done inside HTML tables. The examples below assume a tabular layout, but the PaginatorHelper available in views doesn't always need to be restricted as such.
As mentioned, the PaginatorHelper also offers sorting features which can be easily integrated into your table column headers:
Простой текст// app/views/recipes/list_recipes.ctp<table><tr><th><?php echo $paginator->sort('ID', 'id'); ?></th><th><?php echo $paginator->sort('Title', 'title'); ?></th></tr><?php foreach($data as $recipe): ?><tr><td><?php echo $recipe['Recipe']['id']; ?> </td><td><?php echo $recipe['Recipe']['title']; ?> </td></tr><?php endforeach; ?></table>
The links output from the sort() method of the PaginatorHelper allow users to click on table headers to toggle the sorting of the data by a given field.
It is also possible to sort a column based on associations:
Простой текст<table><tr><th><?php echo $paginator->sort('Title', 'title'); ?></th><th><?php echo $paginator->sort('Author', 'Author.name'); ?></th></tr><?php foreach($data as $recipe): ?><tr><td><?php echo $recipe['Recipe']['title']; ?> </td><td><?php echo $recipe['Author']['name']; ?> </td></tr><?php endforeach; ?></table>
The final ingredient to pagination display in views is the addition of page navigation, also supplied by the PaginationHelper.
Простой текст<!-- Shows the page numbers --><?php echo $paginator->numbers(); ?><!-- Shows the next and previous links --><?phpecho $paginator->prev('« Previous ', null, null, array('class' => 'disabled'));echo $paginator->next(' Next »', null, null, array('class' => 'disabled'));?><!-- prints X of Y, where X is current page and Y is number of pages --><?php echo $paginator->counter(); ?>
The wording output by the counter() method can also be customized using special markers:
Простой текст<?phpecho $paginator->counter(array('format' => 'Page %page% of %pages%, showing %current% records out of%count% total, starting on record %start%, ending on %end%'));?>
To pass all URL arguments to paginator functions, add the following to your view:
Простой текст$paginator->options(array('url' => $this->passedArgs));
Or you can specify which params to pass manually:
Простой текст$paginator->options(array('url' => array("0", "1")));


Коментарии:
Добавить коментарий