Hacer paginación de resultados en Symfony no es muy difícil. Con los siguientes pasos basta y sobra.

Para cualquier módulo que tengamos debemos agregar la instanciación de la clase sfDoctrinePager en la acción. Creamos una «Query» para obtener los registros que necesitamos y se los pasamos al paginador.

public function executeIndex(sfWebRequest $request)
  $max_per_page = 10;
  $query = Doctrine::getTable('NombreClase')->createQuery('n');
  $this->pager = new sfDoctrinePager('NombreClase', $max_per_page);
  $this->pager->setPage($request->getParameter('pag', 1));

Luego, en el «template», usamos la lista de objetos como normalmente la usaríamos.

<?php foreach($pager->getResults() as $item): ?>
  <?php echo $item ?>
<?php endforeach; ?>

3 Responses to “Paginación con Doctrine y Symfony 1.4”

  • morrison

    donde pones ‘nombreclase’ a que te refieres???

  • Hi Guys! I’m trying to flloow this tutorial, but I’m using Doctrine 2 and Codeigniter 2. I have solved all problems but until I got to the validation extension, I think i hit the bar. There seems to be a depreciation issue. The flloowing line of code results in an error:if (doctrine::getTable($model)->$find($value))Here’s the error being shown:ErrorException [ Fatal Error ]: Call to undefined method Doctrine::getTable()It’s seems to me that getTable() is not defined anywhere on Doctrine 2.0, or am i missing something? I tried to Google details, but most of what comes out are from Symfony which is quite appalling. I’m hoping someone could boot me up to this cause it’s really a pain in the ass flloowing a tutorial that was a few versions far apart already. Thank though for the very comprehensive tutorial. I’m really liking it! I hope you’ll do on for Version 2 of both Doctrine and Codeigniter. Thanks!

Add reply