Ver Mensaje Individual
  #50 (permalink)  
Antiguo 04/03/2012, 16:25
Avatar de andresdzphp
andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 9 meses
Puntos: 793
Respuesta: Paginator Zend Framework 2.0 beta

Si eso estuve pensando, no es parte ni de POST ni de GET, le estuve haciendo dump a los métodos y sólo me sale en getEvent(). Voy a ver si mejor lo hago por GET, pero me gusta mucho el ejemplo del router que me diste.

Cómo hago para optimizar el paginador para no pasar todo el result set? qué se puede usar con ese modelo usando TableGateway?

Se está usando este model:

Código PHP:
Ver original
  1. <?php
  2.  
  3. namespace Album\Model;
  4.  
  5. use Zend\Db\TableGateway\TableGateway,
  6.     Zend\Db\Adapter\Adapter,
  7.     Zend\Db\ResultSet\ResultSet;
  8.  
  9. class AlbumTable extends TableGateway
  10. {
  11.     public function __construct(Adapter $adapter = null, $databaseSchema = null,
  12.         ResultSet $selectResultPrototype = null)
  13.     {
  14.         return parent::__construct('cds', $adapter, $databaseSchema,
  15.             $selectResultPrototype);
  16.     }
  17.    
  18.     public function fetchAll()
  19.     {
  20.         $resultSet = $this->select();
  21.         return $resultSet;
  22.     }
  23.    
  24.     public function getAlbum($id)
  25.     {
  26.         $id = (int) $id;
  27.         $rowset = $this->select(array('id' => $id));
  28.         $row = $rowset->current();
  29.         if (!$row) {
  30.             throw new \Exception("Could not find row $id");
  31.         }
  32.         return $row;
  33.     }
  34.    
  35.     public function addAlbum($artist, $title)
  36.     {
  37.         $data = array(
  38.             'artist' => $artist,
  39.             'title' => $title
  40.         );
  41.         $this->insert($data);
  42.     }
  43.    
  44.     public function updateAlbum($id, $artist, $title)
  45.     {
  46.         $data = array(
  47.             'artist' => $artist,
  48.             'title' => $title
  49.         );
  50.         $this->update($data, array('id', $id));
  51.     }
  52.    
  53.     public function deleteAlbum($id) {
  54.         $this->delete(array('id' => $id));
  55.     }
  56. }

y el controller:

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

Gracias por los comentarios.

Saludos.
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP