Propel API
Class

PropelPager

class PropelPager implements Countable, Iterator

PropelPager

Example Usage:

require_once 'propel/util/PropelPager.php';
require_once 'PEACH/Propel/Poem/poemPeer.php';

$c = new Criteria();
$c->addDescendingOrderByColumn(poemPeer::SID);

// with join
$pager = new PropelPager($c, 'poemPeer', 'doSelectJoinPoemUsers', 1, 50);

// without Join

$pager = new PropelPager($c, 'poemPeer', 'doSelect', 1, 50);

Some template:

<p>
Total Pages: <?=$pager->getTotalPages()?> Total Records: <?=$pager->getTotalRecordCount()?>
</p>
<table>
<tr>
<td>
<?if ($link = $pager->getFirstPage):?>
<a href="somescript?page=<?=$link?>"><?=$link?></a>|
<?endif?>
</td>
<td>
<?if ($link = $pager->getPrev()):?>
<a href="somescript?page=<?=$link?>">Previous</a>|
<?endif?>
</td>
<td>
<?foreach ($pager->getPrevLinks() as $link):?>
<a href="somescript?page=<?=$link?>"><?=$link?></a>|
<?endforeach?>
</td>
<td><?=$pager->getPage()?></td>
<td>
<?foreach ($pager->getNextLinks() as $link):?>
| <a href="somescript?page=<?=$link?>"><?=$link?></a>
<?endforeach?>
</td>
<td>
<?if ($link = $pager->getNext()):?>
<a href="somescript?page=<?=$link?>">Last</a>|
<?endif?>
</td>
<td>
<?if ($link = $pager->getLastPage()):?>
<a href="somescript?page=<?=$link?>"><?=$link?></a>|
<?endif?>
</td>
</tr>
</table>
<table id="latestPoems">
<tr>
<th>Title</th>
<th>Auteur</th>
<th>Date</th>
<th>comments</th>
</tr>
<?foreach ($pager->getResult() as $poem):?>
<tr>
<td><?=$poem->getTitle()?></td>
<td><?=$poem->getPoemUsers()->getUname()?></td>
<td><?=$poem->getTime()?></td>
<td><?=$poem->getComments()?></td>
</tr>
<?endforeach?>
</table>

Methods

__construct(Criteria $c = null, string $peerClass = null, string $peerSelectMethod = null, int $page = 1, int $rowsPerPage = 25)

Create a new Propel Pager.

void setCriteria(Criteria $c)

Set the criteria for this pager.

Criteria getCriteria()

Return the Criteria object for this pager.

void setPeerClass(string $class)

Set the Peer Classname

string getPeerClass()

Return the Peer Classname.

void setPeerMethod(string $method)

Set the Peer select method.

string getPeerMethod()

Return the Peer select method.

void setPeerSelectMethod(string $method)

Set the Peer select method.

string getPeerSelectMethod()

Return the Peer select method.

setPeerCountMethod(string $method)

Sets the Count method.

getPeerCountMethod()

Return the Peer count method.

mixed getResult()

Get the paged resultset

int getFirstPage()

Get the first page

boolean atFirstPage()

Convenience method to indicate whether current page is the first page.

int getLastPage()

Get last page

boolean atLastPage()

Convenience method to indicate whether current page is the last page.

int getTotalPages()

get total pages

array getPrevLinks(int $range = 5)

get an array of previous id's

array getNextLinks(int $range = 5)

get an array of next id's

bool isLastPageComplete()

Returns whether last page is complete

mixed getPrev()

get previous id

mixed getNext()

get next id

void setPage(int $page)

Set the current page number (First page is 1).

int getPage()

Get current page.

setRowsPerPage(int $r)

Set the number of rows per page.

int getRowsPerPage()

Get number of rows per page.

int getTotalRecordCount()

Gets the total number of (un-LIMITed) records.

setStart(int $v)

Sets the start row or offset.

void setMax(int $v)

Sets max rows (limit).

int count()

Returns the count of the current page's records

mixed current()

Returns the current element of the iterator

int key()

Returns the current key of the iterator

void next()

Advances the iterator to the next element

void rewind()

Resets the iterator to the first element

boolean valid()

Checks if the current key exists in the container

Details

at line 123
public __construct(Criteria $c = null, string $peerClass = null, string $peerSelectMethod = null, int $page = 1, int $rowsPerPage = 25)

Create a new Propel Pager.

Parameters

Criteria $c
string $peerClass The name of the static Peer class.
string $peerSelectMethod The name of the static method for selecting content from the Peer class.
int $page The current page (1-based).
int $rowsPerPage The number of rows that should be displayed per page.

at line 141
public void setCriteria(Criteria $c)

Set the criteria for this pager.

Parameters

Criteria $c

Return Value

void

at line 150
public Criteria getCriteria()

Return the Criteria object for this pager.

Return Value

Criteria

at line 161
public void setPeerClass(string $class)

Set the Peer Classname

Parameters

string $class

Return Value

void

at line 170
public string getPeerClass()

Return the Peer Classname.

Return Value

string

at line 183
public void setPeerMethod(string $method)

Set the Peer select method.

This exists for legacy support, please use setPeerSelectMethod().

Parameters

string $method The name of the static method to call on the Peer class.

Return Value

void

See also

setPeerSelectMethod()

at line 195
public string getPeerMethod()

Return the Peer select method.

This exists for legacy support, please use getPeerSelectMethod().

Return Value

string

See also

getPeerSelectMethod()

at line 206
public void setPeerSelectMethod(string $method)

Set the Peer select method.

Parameters

string $method The name of the static method to call on the Peer class.

Return Value

void

at line 215
public string getPeerSelectMethod()

Return the Peer select method.

Return Value

string

at line 226
public setPeerCountMethod(string $method)

Sets the Count method.

This is set based on the Peer method, for example if Peer method is doSelectJoin*() then the
count method will be doCountJoin*().

Parameters

string $method The name of the static method to call on the Peer class.

at line 234
public getPeerCountMethod()

Return the Peer count method.

at line 263
public mixed getResult()

Get the paged resultset

Return Value

mixed $rs

at line 294
public int getFirstPage()

Get the first page

For now I can only think of returning 1 always.
It should probably return 0 if there are no pages

Return Value

int 1

at line 304
public boolean atFirstPage()

Convenience method to indicate whether current page is the first page.

Return Value

boolean

at line 314
public int getLastPage()

Get last page

Return Value

int $lastPage

at line 329
public boolean atLastPage()

Convenience method to indicate whether current page is the last page.

Return Value

boolean

at line 339
public int getTotalPages()

get total pages

Return Value

int $this->pages

get an array of previous id's

Parameters

int $range

Return Value

array $links

get an array of next id's

Parameters

int $range

Return Value

array $links

at line 402
public bool isLastPageComplete()

Returns whether last page is complete

Return Value

bool Last page complete or not

at line 412
public mixed getPrev()

get previous id

Return Value

mixed $prev

at line 426
public mixed getNext()

get next id

Return Value

mixed $next

at line 440
public void setPage(int $page)

Set the current page number (First page is 1).

Parameters

int $page

Return Value

void

at line 451
public int getPage()

Get current page.

Return Value

int

at line 460
public setRowsPerPage(int $r)

Set the number of rows per page.

Parameters

int $r

at line 471
public int getRowsPerPage()

Get number of rows per page.

Return Value

int

at line 492
public int getTotalRecordCount()

Gets the total number of (un-LIMITed) records.

This method will perform a query that executes un-LIMITed query.

Return Value

int Total number of records - disregarding page, maxrows, etc.

at line 522
public setStart(int $v)

Sets the start row or offset.

Parameters

int $v

at line 532
public void setMax(int $v)

Sets max rows (limit).

Parameters

int $v

Return Value

void

at line 541
public int count()

Returns the count of the current page's records

Return Value

int

at line 550
public mixed current()

Returns the current element of the iterator

Return Value

mixed

at line 562
public int key()

Returns the current key of the iterator

Return Value

int

at line 571
public void next()

Advances the iterator to the next element

Return Value

void

at line 580
public void rewind()

Resets the iterator to the first element

Return Value

void

at line 589
public boolean valid()

Checks if the current key exists in the container

Return Value

boolean