Как получить общее количество записей, извлеченных с нумерацией страниц в CakePHP 3? - PullRequest
0 голосов
/ 21 декабря 2018

У меня проблема в CakePHP 3 для правильной нумерации страниц.

Как получить общее количество записей, извлеченных с нумерацией страниц в CakePHP 3?

1 Ответ

0 голосов
/ 21 декабря 2018

Это может помочь вам.В вашем контроллере, например, UsersController.php сделайте нумерацию страниц следующим образом:

public function index()
{

    //set your pagination limit 10
    $this->paginate = [
        'limit' => 10
    ];

   //query all users
   $users = $this->paginate($this->Users->find('all'));

    //pass to template
    $this->set(compact('users'));

}

В вашем шаблонном представлении т.е.

<div class="users index large-9 medium-8 columns content">
<h3><?= __('Users') ?></h3>
<table cellpadding="0" cellspacing="0" border="1">
    <thead>
    <tr>
        <th scope="col"><?= $this->Paginator->sort('id') ?></th>
        <th scope="col"><?= $this->Paginator->sort('fullname') ?></th>
        <th scope="col"><?= $this->Paginator->sort('email') ?></th>
        <th scope="col"><?= $this->Paginator->sort('handphone') ?></th>
        <th scope="col" class="actions"><?= __('Actions') ?></th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($users as $user): ?>
        <tr>
            <td><?= $this->Number->format($user->uid) ?></td>
            <td><?= h($user->fullname) ?></td>
            <td><?= h($user->email) ?></td>
            <td><?= h($user->handphone) ?></td>
            <td class="actions">
                <?= $this->Html->link(__('View'), ['action' => 'view', $user->id]) ?>
                <?= $this->Html->link(__('Edit'), ['action' => 'edit', $user->id]) ?>   
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>
<div class="paginator">
    <ul class="pagination">
        <?= $this->Paginator->first('<< ' . __('first')) ?>
        <?= $this->Paginator->prev('< ' . __('previous')) ?>
        <?= $this->Paginator->numbers() ?>
        <?= $this->Paginator->next(__('next') . ' >') ?>
        <?= $this->Paginator->last(__('last') . ' >>') ?>
    </ul>
    <p><?= $this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')]) ?></p>
</div>

Измените выше переменную соответственно, чтобы соответствовать объектам вашей таблицы (имя столбцов).

СОВЕТЫ: ​​Если вы используетеКоманда Bake CakePHP, вы получите всю эту нумерацию страниц по умолчанию

...