开发者

Symfony foreach show numbering

开发者 https://www.devze.com 2023-03-08 16:40 出处:网络
I have a form show a list of id and emails from database with the code below. I wonder if there anyway to include numbering in order instead of using the id.

I have a form show a list of id and emails from database with the code below. I wonder if there anyway to include numbering in order instead of using the id.

<?php foreach($pager->getResults() as $user): ?>
  <tr>
    <td><?php echo $user->getId() ?></td>
    <td><?php echo $开发者_如何转开发user->getEmail() ?></td>
  </tr>
<?php endforeach; ?>

Method Using: Symfony form, Pagination.


I've never tested this code, but i think it should work

<?php $i = ($pager->getPage()-1)*$pager->getMaxPerPage()+1; ?>
<?php foreach($pager->getResults() as $user): ?>
  <tr>
    <td><?php echo $i ?></td>
    <td><?php echo $user->getEmail() ?></td>
  </tr>
<?php $i++; ?>
<?php endforeach; ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消