Вход Регистрация
* 3KZO

Пагинация

  1. <?php
  2.  
  3. /**
  4.  * Пагинация
  5.  */
  6. class pagination
  7. {
  8.  
  9. public
  10. /** @var int
  11.   */
  12. $page,
  13.  
  14. /** @var int
  15.   */
  16. $pages,
  17.  
  18. /** @var int
  19.   */
  20. $_at;
  21.  
  22. /**
  23.   * Экземпляр
  24.   */
  25. function __construct($items_count = 0, $items_per_page = 10)
  26. {
  27.  
  28. $this->page = intval($_GET['page']);
  29. //
  30. if ($this->page < 1)
  31. $this->page = 1;
  32.  
  33. $this->pages= ceil($items_count/$items_per_page);
  34.  
  35. //
  36. if ($_GET['page'] == 'end' || $this->page > $this->pages)
  37. $this->page = $this->pages;
  38.  
  39. $this->_at = $this->page * $items_per_page - $items_per_page;
  40.  
  41. }
  42.  
  43. /**
  44.   * Отображение
  45.   */
  46. public function display($ref = '')
  47. {
  48.  
  49. // Первая страница
  50. if ($this->page == 1)
  51. $output .= '1';
  52.  
  53. if ($this->page != 1)
  54. $output .= '<a href="' . $ref . 'page=1">1</a> ';
  55.  
  56. // Наш паравозик со страницами
  57. for ($i = -3; $i <= 3; $i++)
  58. {
  59.  
  60. if (($this->page + $i) > 1 && ($this->page + $i) < $this->pages)
  61. {
  62. //
  63. if ($i == -3 && ($this->page + $i) > 2)
  64. $output .= '..';
  65. //
  66. if (($this->page + $i) > 0)
  67. $output .= (($this->page + $i) == $this->page) ? $this->page : ' <a href="' . $ref . 'page=' . ($this->page + $i) . '">' . ($this->page + $i) . '</a> ';
  68. //
  69. if ($i == 3 && ($this->page + $i) < ($this->pages - 1))
  70. $output .= '..';
  71.  
  72. }
  73.  
  74. }
  75.  
  76. // Последняя страница
  77. if ($this->page != $this->pages)
  78. $output .= ' <a href="' . $ref . 'page=end">' . $this->pages . '</a>';
  79.  
  80. if ($this->page == $this->pages)
  81. $output .= $this->pages;
  82.  
  83. echo $output;
  84.  
  85. }
  86.  
  87. }
» Описание: Пагинация, изначально писалась для моего движка. Получилась как на ДЦМС, т.к пагинация там очень удо
» Время добавления: 13 Окт 2014 в 09:23
» Посмотров: 1413
» textarea
» Рейтинг: [+0 | -0]
Комментарии [1]
Онлайн: 2
Реклама