I am using Cygnite PHP Framework and generated CRUD application using Cygnite CRUD generator. I changed pagination limit to 10 per page in my model class.
Now the problem is,
In the first page serial number is displaying 1-10 but when I am clicking on the next page, though records are different it is reseting the serial number back to 1-10 again. It should be (Second page) 11-20.
My view page:
<?php
if (count($this->records) > 0) {
$i = 1;
$rowType = null;
foreach ($this->records as $key => $value) {
$rowType = ($i % 2 == 0) ? 'even' : 'odd';
?>
<tr class='<?php echo $rowType; ?>'>
<td> <?php echo $i; ?></td>
..............
</tr>
}
}
?>
<div ><?php echo $this->links; ?> </div>
How to fix it ?
Thanks!
Hope below code will help you.
Step1: Open /apps/views/user/index.view.php
Step 2: In this page inside top of the view page add below code to include.
use Cygnite\Common\UrlManager\Url;
use Apps\Models\User;
$user = new User;
Step 3: Now go inside if condition
if (count($this->records) > 0) {
replace $i with below code.
if (Url::segment(2) == '' || Url::segment(3) == '' || Url::segment(3) == 1 ) {
$i =1;
} else {
$i = (Url::segment(3) - 1) * $user->perPage + 1;
}
Step 4: That's all. Now run the application it will display serial number correctly into the grid.
Cheers!