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

De hecho para probar lo que digo hice esta prueba, el controller:
Código PHP:
Ver original
  1. <?php
  2.  
  3. namespace Album\Controller;
  4.  
  5. use Album\Model\DbTable\AlbumTable,
  6.     Zend\Mvc\Controller\ActionController,
  7.     Zend\Paginator\Paginator,
  8.     Zend\View\Helper\PaginationControl,
  9.     Zend\View\Renderer;
  10.  
  11.  
  12. class ListController extends ActionController
  13. {
  14.     protected $albumTable;
  15.     protected $view;
  16.    
  17.     public function setView(\Zend\View\Renderer $view)
  18.     {
  19.         $this->view = $view;
  20.        
  21.         return $this;
  22.     }
  23.    
  24.     public function getView()
  25.     {
  26.         return $this->view;
  27.     }
  28.    
  29.     public function setAlbumTable(AlbumTable $albumTable)
  30.     {
  31.         $this->albumTable = $albumTable;
  32.        
  33.         return $this;
  34.     }
  35.    
  36.     public function getAlbumTable()
  37.     {
  38.         return $this->albumTable;
  39.     }
  40.    
  41.     public function indexAction()
  42.     {
  43.         $albums = $this->getAlbumTable()->fetchAll();
  44.         $matches = $this->getEvent()->getRouteMatch();
  45.         $nPage = $matches->getParam('page', 1);
  46.        
  47.         PaginationControl::setDefaultViewPartial('paginator.phtml');
  48.        
  49.         $paginator = Paginator::factory($albums);
  50.         $paginator->setDefaultItemCountPerPage(5);
  51.         $paginator->setCurrentPageNumber($nPage);
  52.         $paginator->setView($this->getView());
  53.        
  54.         return array('albums' => $paginator);
  55.     }
  56. }

El DI:
Código PHP:
Ver original
  1. 'alias' => array(
  2.                 'album-list' => 'Album\Controller\ListController'
  3.             ),
  4.             'Album\Controller\ListController' => array (
  5.                 'parameters' => array (
  6.                    'albumTable' => 'Album\Model\DbTable\AlbumTable',
  7.                    'view' => 'view'
  8.                 )
  9.             ),

La 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->albums; ?>

y funciona correctamente