tags:

views:

199

answers:

1

I have wrote universal script to get all rows from Doctrine Table Models, but if rows amount is too large, i get exception:

Cannot define NULL as part of query when defining 'offset'.

Running script:

$table = new JV_Model_StoreOrder();
$this->data['list'] = $table->getTable()->findAll()->toArray();

I understand from the error above is due to the large number of entries in the table (> 20 000). So I decided to make a paginator to break records on the pages of 100 pieces.

Could you help me, how can I do something like that:

...
$total_amount = $table->getTable()->count();
$this->data['list'] = $table->getTable()->offset(0)->limit(100)
->findAll()->toArray();
...
+1  A: 

Doctrine has it's own Pagination component:

Example from Doctrine manual:

// Defining initial variables
$currentPage = 1;
$resultsPerPage = 50;

// Creating pager object
$pager = new Doctrine_Pager(
      Doctrine_Query::create()
            ->from( 'User u' )
            ->leftJoin( 'u.Group g' )
            ->orderby( 'u.username ASC' ),
      $currentPage, // Current page of request
      $resultsPerPage // (Optional) Number of results per page. Default is 25
);
Gordon