Pagination in fuelPHP

We always need pagination for displaying many records.

fuelPHP makes this easy for us:

$countQuotes = count(Model_Quote::query()->where(‘user_id’, Auth::instance()->get(‘id’))->get());
$pagination = Pagination::forge(‘pagedquotes’, array(
‘pagination_url’ => ‘/quotes/’,
‘total_items’ => $countQuotes,
‘per_page’ => 10,
‘uri_segment’ => ‘page’,

$data[‘quotes’] = Model_Quote::query()->where(‘user_id’, Auth::instance()->get(‘id’))->limit($pagination->per_page)->offset($pagination->offset)->get();

$data[‘pagination’] = $pagination->render();


And in the View:

<table id="quotesTable" class="table table-striped">
<th><?php echo Form::select(‘client_id’, Input::post(‘client_id’, isset($client_id) ? $client_id : ”), array(”=>’All Clients’) + $user->clients, array(‘class’ => ‘span2 filter’)); ?></th>
<th>Status<?php //echo Form::select(‘status_id’, Input::post(‘status_id’, isset($status_id) ? $status_id : ”), array(”=>’All Statuses’) + $user->settings->quotestatuses, array(‘class’ => ‘span2 filter’)); ?></th>
$quotesTotal = 0;
foreach ($quotes as $quote)
$quotesTotal += $quote->cost;
<tr data-client_id="<?php echo $quote->client->id; ?>" data-status_id="<?php echo $quote->quotestatus->id; ?>">
<td><small><?php echo date("m/d/Y", $quote->created_at); ?></small></td>
<td><strong><?php echo $quote->name; ?></strong><br/><small><?php echo $quote->ref; ?></small></td>
<td><a href="/clients/view/<?php echo $quote->client->id; ?>"><strong><?php echo $quote->client->company_name; ?></strong><br/><?php echo $quote->client->name; ?></a></td>
<td><?php echo $quote->status->name; ?></td>
<td><?php echo $user->currency_symbol; ?><?php echo number_format($quote->cost, 2); ?></td>

<li><a href="/quotes/view/<?php echo $quote->id; ?>"><i class="icon-eye-open" title="View"></i> View Quote</a></li>
<li><a href="/quotes/print/<?php echo $quote->id; ?>"><i class="icon-print" title="View"></i> Print Quote</a></li>
<li class="divider"></li>
<li><a href="/quotes/edit/<?php echo $quote->id; ?>"><i class="icon-wrench" title="Edit"></i> Edit</a></li>
<li><a href="/quotes/delete/<?php echo $quote->id; ?>" onclick="return confirm(‘Are you sure?’);"><i class="icon-trash" title="Delete"></i> Delete</a></li>

<td colspan="5"></td>
<td><?php echo $user->settings->currency_symbol; ?><?php echo number_format($quotesTotal, 2); ?></td>

No Comments

You can leave the first : )

Leave a Reply

Your email address will not be published. Required fields are marked *