- Click the ‘检索’ button
- Click the ‘next>’ button
- The null value in the path has been deleted, I don’t want to delete it.
- cakephp5.x>users
UsersController.php
protected array $paginate = [
'limit' => 5,
];
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->Users->find();
$users = $this->paginate($query);
$this->set(compact('users'));
}
…/templates/Users/index.php
<!--enquiry form -->
<?= $this->Form->create(null, ['type' => 'get']); ?>
<?= $this->Form->control('email', [
'label' => '邮箱:',
'type' => 'text',
'default' => '',
'value' => $this->getRequest()->getQuery('email'),
]); ?>
<?= $this->Form->button('检索'); ?>
<?= $this->Form->end(); ?>
...
<!-- page -->
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->first('<< ' . __('first')) ?>
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->counter() ?>
<?= $this->Paginator->next(__('next') . ' >', ) ?>
<?= $this->Paginator->last(__('last') . ' >>') ?>
</ul>
<p><?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
</div>
Problem description:
检索>btn 》url
http://localhost:8765/users?email=
$this->Paginator->next() 》 url
http://localhost:8765/users?page=2
When the condition ‘email’ is null, the pagination button removes it.
Hope to keep null values
http://localhost:8765/users?email=&page=2