Skip to content

Instantly share code, notes, and snippets.

@yickson
Last active January 30, 2016 02:09
Show Gist options
  • Save yickson/c494a7949b5e074b0b74 to your computer and use it in GitHub Desktop.
Save yickson/c494a7949b5e074b0b74 to your computer and use it in GitHub Desktop.
Paginador KumbiaPHP con estilo de Bootstrap 3

##Bienvenido a KumbiaPHP -> Bailando con el código

Para utilizar este Gist y adaptarlo a tu framework solo debes copiar el archivo paginador.phtml y colocarlo en esta sección "app/views/_shared/partials/" lo colocas ahí con el mismo nombre que refleja el archivo.

Como esto es un partial de Kumbia solo debes llamarlo en la vista que así lo deseas, por supuesto también debes tener bien diseñado el controlador y el modelo que llamará tu consulta SQL.

View :: partial ( 'paginador' , false , array ( 'page' => $clientes ,'show' => 5 , 'url' => 'administrador/ver' )) //url debes cambiarlo por tu url donde se muestra el paginado Controller/Action
<?php
/**
* KumbiaPHP web & app Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://wiki.kumbiaphp.com/Licencia
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@kumbiaphp.com so we can send you a copy immediately.
*
* Paginador "classic" para aplicaciones
*
* Parametros del paginador:
* page: objeto obtenido al invocar al paginador
* show: numero de paginas que se mostraran en el paginador
* url: url para la accion que efectua la paginacion, por defecto "module/controller/page/"
* y se envia por parametro el numero de pagina
*
* @category Kumbia
* @package Partials
* @copyright Copyright (c) 2005-2015 Kumbia Team (http://www.kumbiaphp.com)
* @license http://wiki.kumbiaphp.com/Licencia New BSD License
*/
if(!isset($url)) {
extract(Router::get());
$url = "$controller/page";
if($module) {
$url = "$module/$url";
}
}
if(!isset($show)) {
$show = 10;
}
$half = floor($show/2);
// Calculando el inicio de paginador centrado
if ($page->current <= $half) {
$start = 1;
} elseif (($page->total - $page->current)<$half) {
$start = $page->total - $show + 1;
if($start < 1) $start = 1;
} else {
$start = $page->current - $half;
}
?>
<nav>
<ul class="pagination">
<?php if($page->prev==1) echo '<li>' . Html::link("$url/", '<span aria-hidden="true">&laquo;</span>', 'title="Ir a la pág. anterior" class="nextprev" rel="prev" aria-label="Previous"') . '</li>'; // Se coloca el enlace sin número de página para la pagina 1
elseif($page->prev) echo '<li>' . Html::link("$url/$page->prev/", '<span aria-hidden="true">&laquo;</span>', 'title="Ir a la pág. anterior" class="nextprev" rel="prev"') . '</li>'; ?>
<?php if($start==1){ //se coloca el link sin número de página para la página 1
$start = 2;
$show -= 1;
echo $page->current==1 ? '<li class="active"><a href="#">1</a></li>' : '<li>'.Html::link("$url/", '1').'</li>';
}?>
<?php for($i=$start; $i<=$page->total && $i<($start + $show); $i++): ?>
<?php echo $i==$page->current ? "<li class='active'><a href='#'>$i</a></li>" : '<li>'.Html::link("$url/$i/", $i).'</li>' ?>
<?php endfor ?>
<?php if($page->next) echo '<li>' . Html::link("$url/$page->next/", '<span aria-hidden="true">&raquo;</span>', 'title="Ir a la pág. siguiente" class="nextprev" rel="next" aria-label="Next"') . '</li>'; ?>
</ul>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment