Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZF] Pager
Forum PHP.pl > Forum > PHP > Frameworki
Balon
Czy istnieje jakaś klasa pagera?
Muszę coś na szybko trzasnąć i potrzebowałbym czegoś porządnego i dobrego.
W googlach znalazłem jeden, ale jakiś świetny to on nie był.

pozdrawiam
marcio
Pager Nospor'a

http://forumphp.nq.pl/index.php?showtopic=...t=0&start=0
party
view/helpers/Pagination.php
CODE
<?php

class My_View_Helper_Pagination
{
private $intRows = 0;
private $intLimit = 0;
private $intPage = 0;

private $blnFailure = false;

private $strController;
private $strAction;

private $_view;


public function setView( $view ) {
$this -> _view = $view;
}

public function pagination()
{
return $this;
}

public function SetOptions( $intPage, $intLimit, $intRows, $strController, $strAction )
{
if( isset( $intPage ) && isset( $intLimit ) && isset( $intRows ) )
{
$this -> intRows = $intRows;
$this -> intLimit = $intLimit;
$this -> intPage = $intPage;
$this -> strController = $strController;
$this -> strAction = $strAction;
}
else
{
$this -> blnFailure = true;
}
}

public function Render()
{
if( $this -> blnFailure === true )
{
return 'Pagination: Upewnij sie, ze zdefiniowales wszystkie opcje w Twojej akcji kontrolera';
}
else
{
$this -> _view -> pag_intPages = ceil( $this -> intRows / $this -> intLimit );
$this -> _view -> pag_intPage = $this -> intPage;
$this -> _view -> pag_strContoller = $this -> strController;
$this -> _view -> pag_strAction = $this -> strAction;

return $this -> _view -> render( 'pagination.phtml' );
}
}
}


view/scripts/pagination.phtml:
  1. <div class="PaginationParent">
  2. <ul class="Pagination">
  3. <li>Strony: </li>
  4. <li>
  5. <?php if( $this -> pag_intPage < 3 ): ?>
  6. <img src="<?= $this -> baseUrl ?>/public/images/icons/first_.gif" alt="" />
  7. <?php else: ?>
  8. <a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/1"><img src="<?= $this -> baseUrl ?>/public/images/icons/first.gif" alt="" /></a>
  9. <?php endif; ?>
  10. </li>
  11. <li>
  12. <?php if( $this -> pag_intPage == 1 ): ?>
  13. <img src="<?= $this -> baseUrl ?>/public/images/icons/previous_.gif" alt="" />
  14. <?php else: ?>
  15. <a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/<?= $this -> pag_intPage - 1 ?>"><img src="<?= $this -> baseUrl ?>/public/images/icons/previous.gif" alt="" /></a>
  16. <?php endif; ?>
  17. </li>
  18. <?php
  19. if( $this -> pag_intPages < 9 ):
  20. for( $intI = 1; $intI <= $this -> pag_intPages; $intI++ ):
  21. ?>
  22. <li<?php if( $this -> pag_intPage == $intI ): ?> class="PaginationActual"<?php endif; ?>>
  23. <?php
  24. if( $this -> pag_intPage != $intI ):
  25. ?>
  26. <a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/<?= $intI ?>"><?= $intI ?></a>
  27. <?php
  28. else:
  29. echo( $intI );
  30. endif;
  31. ?>
  32. </li>
  33. <?php
  34. endfor;
  35. else:
  36. if( $this -> pag_intPage < 5 ):
  37. $intShow = ( $this -> pag_intPage > 2 ) ? $this -> pag_intPage + 1 : 3;
  38. for( $intI = 1; $intI <= $intShow; $intI++ ):
  39. ?>
  40. <li<?php if( $this -> pag_intPage == $intI ): ?> class="PaginationActual"<?php endif; ?>>
  41. <?php
  42. if( $this -> pag_intPage != $intI ):
  43. ?>
  44. <a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/<?= $intI ?>"><?= $intI ?></a>
  45. <?php
  46. else:
  47. echo( $intI );
  48. endif;
  49. ?>
  50. </li>
  51. <?php
  52. endfor;
  53. ?>
  54. <li>...</li>
  55. <li><a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/<?= $this -> pag_intPages ?>"><?= $this -> pag_intPages ?></a></li>
  56. <?php
  57. elseif( $this -> pag_intPage >= 5 && $this -> pag_intPage <= ( $this -> pag_intPages - 4 ) ):
  58. ?>
  59. <li><a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/1">1</a></li>
  60. <li>...</li>
  61. <?php
  62. for( $intI = ( $this -> pag_intPage - 2 ); $intI <= ( $this -> pag_intPage + 2 ); $intI ++ ):
  63. ?>
  64. <li<?php if( $this -> pag_intPage == $intI ): ?> class="PaginationActual"<?php endif; ?>>
  65. <?php
  66. if( $this -> pag_intPage != $intI ):
  67. ?>
  68. <a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/<?= $intI ?>"><?= $intI ?></a>
  69. <?php
  70. else:
  71. echo( $intI );
  72. endif;
  73. ?>
  74. </li>
  75. <?php
  76. endfor;
  77. ?>
  78. <li>...</li>
  79. <li><a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/<?= $this -> pag_intPages ?>"><?= $this -> pag_intPages ?></a></li>
  80. <?php
  81. elseif( $this -> pag_intPage > ( $this -> pag_intPages - 4 ) ):
  82. ?>
  83. <li><a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/1">1</a></li>
  84. <li>...</li>
  85. <?php
  86. $intShow = ( $this -> pag_intPage < ( $this -> pag_intPages - 1 ) ) ? $this -> pag_intPage - 1 : $this -> pag_intPages - 2;
  87. for( $intI = $intShow; $intI <= $this -> pag_intPages; $intI ++ ):
  88. ?>
  89. <li<?php if( $this -> pag_intPage == $intI ): ?> class="PaginationActual"<?php endif; ?>>
  90. <?php
  91. if( $this -> pag_intPage != $intI ):
  92. ?>
  93. <a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/<?= $intI ?>"><?= $intI ?></a>
  94. <?php
  95. else:
  96. echo( $intI );
  97. endif;
  98. ?>
  99. </li>
  100. <?php
  101. endfor;
  102. endif;
  103. endif;
  104. ?>
  105. <li>
  106. <?php if( ( $this -> pag_intPages - $this -> pag_intPage ) == 0 ): ?>
  107. <img src="<?= $this -> baseUrl ?>/public/images/icons/next_.gif" alt="" />
  108. <?php else: ?>
  109. <a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/<?= $this -> pag_intPage + 1 ?>"><img src="<?= $this -> baseUrl ?>/public/images/icons/next.gif" alt="" /></a>
  110. <?php endif; ?>
  111. </li>
  112. <li>
  113. <?php if( ( $this -> pag_intPages - $this -> pag_intPage ) < 2 ): ?>
  114. <img src="<?= $this -> baseUrl ?>/public/images/icons/last_.gif" alt="" />
  115. <?php else: ?>
  116. <a href="<?= $this -> baseUrl ?>/<?= $this -> pag_strController ?>/<?= $this -> pag_strAction ?>/p/<?= $this -> pag_intPages ?>"><img src="<?= $this -> baseUrl ?>/public/images/icons/last.gif" alt="" /></a>
  117. <?php endif; ?>
  118. </li>
  119. </ul>
  120. <div class="Clear"> </div>
  121. </div>


plik kontrolera:
CODE

<?php

class TwojController extends Front_Controller_Action
{
// ...

function indexAction()
{
$intPage = $this -> _request -> getParam( 'p' ); // numer strony znajduje sie w parametrze "p"
$intPage = ( !empty( $intPage ) ) ? $intPage : 1;
$intLimit = ... // tutaj wyciagnij sobie limit rekordow na stronie z configa czy cos

$this -> view -> pag_intRows = (int)$this -> CountRows(); // zliczenie wszystkich rekordów
$this -> view -> pag_intLimit = $intLimit;
$this -> view -> pag_intPage = $intPage;
$this -> view -> pag_strController = 'twoj'; //nazwa kontrolera
$this -> view -> pag_strAction = 'index'; //nazwa akcji
}


index.phtml: w miejscu gdzie chcesz wyswietlic stronnicowanie
CODE

<?php
$this -> pagination() -> SetOptions( $this -> pag_intPage, $this -> pag_intLimit, $this -> pag_intRows, $this -> pag_strController, $this -> pag_strAction );
print( $this -> pagination() -> Render() );
?>
Balon
Z pierwszym pokombinuje. A ten drugi coś nie chce śmigać winksmiley.jpg Scrashował mi apache na localu.
Znalazłem rozwiązanie. Napisałem własny pager winksmiley.jpg Działa aż miło!
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.