Ver Mensaje Individual
  #22 (permalink)  
Antiguo 16/02/2012, 13:39
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Paginator Zend Framework 2.0 beta

Acabo de hacer una pequeña prueba y no tuve que hacer muchos cambios, el DI:
Código PHP:
Ver original
  1. 'di' => array(
  2.         'instance' => array(
  3.             'alias' => array(
  4.                 'album-list' => 'Album\Controller\ListController'
  5.             ),
  6.             'Album\Controller\ListController' => array (
  7.                 'parameters' => array (
  8.                    'albumTable' => 'Album\Model\DbTable\AlbumTable'
  9.                 )
  10.             ),
  11.             'Album\Model\DbTable\AlbumTable' => array (
  12.                 'parameters' => array (
  13.                     'config' => 'Zend\Db\Adapter\PdoMysql'
  14.                 )
  15.             ),
  16.             'Zend\Db\Adapter\PdoMysql' => array (
  17.                 'parameters' => array (
  18.                     'config' => array (
  19.                         'host' => 'localhost',
  20.                         'username' => 'root',
  21.                         'password' => 'mypwd',
  22.                         'dbname' => 'test'
  23.                     )
  24.                 )
  25.             ),
  26.             'Zend\View\PhpRenderer' => array(
  27.                 'parameters' => array(
  28.                     'options'  => array(
  29.                         'script_paths' => array(
  30.                             'Album' => __DIR__ . '/../views',
  31.                         ),
  32.                     ),
  33.                 ),
  34.             ),
  35.             'Zend\Mvc\Router\RouteStack' => array(
  36.                 'parameters' => array(
  37.                     'routes' => array(
  38.                         'album-list' => array(
  39.                             'type'    => 'Zend\Mvc\Router\Http\Segment',
  40.                             'options' => array(
  41.                                 'route' => '/album[/:page]',
  42.                                 'constraints' => array(
  43.                                     'page' => '[0-9]+',
  44.                                 ),
  45.                                 'defaults' => array(
  46.                                     'controller' => 'album-list',
  47.                                     'action'     => 'index',
  48.                                     'page'       => 1
  49.                                 ),
  50.                             ),
  51.                         ),
  52.                     ),
  53.                 ),
  54.             ),
  55.         ),
  56.     ),

Controlador:
Código PHP:
Ver original
  1. public function indexAction()
  2.     {
  3.         $albums = $this->getAlbumTable()->fetchAll();
  4.         $matches = $this->getEvent()->getRouteMatch();
  5.         $nPage = $matches->getParam('page', 1);
  6.        
  7.         PaginationControl::setDefaultViewPartial('paginator.phtml');
  8.        
  9.         $paginator = Paginator::factory($albums);
  10.         $paginator->setDefaultItemCountPerPage(5);
  11.         $paginator->setCurrentPageNumber($nPage);
  12.        
  13.         return array('albums' => $paginator);
  14.     }

Vista:
Código PHP:
Ver original
  1. <h1>Albums</h1>
  2. <ul>
  3. <?php foreach ($this->albums as $album) { ?>
  4.     <li><?php echo $album->album_id; ?> - <?php echo $album->album; ?></li>
  5. <?php } ?>
  6. </ul>
  7. <?php echo $this->paginationControl($this->albums, 'Sliding'); ?>

Paginador:
Código PHP:
Ver original
  1. <?php if ($this->pageCount): ?>
  2. <div class="paginationControl">
  3. <?php echo $this->firstItemNumber; ?> - <?php echo $this->lastItemNumber; ?>
  4.  de <?php echo $this->totalItemCount; ?>
  5.  
  6. <!-- First page link -->
  7. <?php if (isset($this->previous)): ?>
  8.   <a href="<?php echo $this->url('album-list', array('page' => $this->first)); ?>">
  9.     Primero
  10.   </a> |
  11. <?php else: ?>
  12.   <span class="disabled">First</span> |
  13. <?php endif; ?>
  14.  
  15. <!-- Previous page link -->
  16. <?php if (isset($this->previous)): ?>
  17.   <a href="<?php echo $this->url('album-list', array('page' => $this->previous)); ?>">
  18.     &lt; Anterior
  19.   </a> |
  20. <?php else: ?>
  21.   <span class="disabled">&lt; Anterior</span> |
  22. <?php endif; ?>
  23.  
  24. <!-- Next page link -->
  25. <?php if (isset($this->next)): ?>
  26.   <a href="<?php echo $this->url('album-list', array('page' => $this->next)); ?>">
  27.     Siguiente &gt;
  28.   </a> |
  29. <?php else: ?>
  30.   <span class="disabled">Siguiente &gt;</span> |
  31. <?php endif; ?>
  32.  
  33. <!-- Last page link -->
  34. <?php if (isset($this->next)): ?>
  35.   <a href="<?php echo $this->url('album-list', array('page' => $this->last)); ?>">
  36.     Último
  37.   </a>
  38. <?php else: ?>
  39.   <span class="disabled">Último</span>
  40. <?php endif; ?>
  41.  
  42. </div>
  43. <?php endif; ?>