CodeIgniter4: Bug: [Pager] Knocks down variables for View
PHP Version
8.2
CodeIgniter4 Version
4.3.6
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter
)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
cli-server (PHP built-in webserver)
Database
No response
What happened?
I couldn’t determine exactly why it works in one place and not in another. When calling $pager->links(), my parameters set inside the template disappear. I added a “title”, but it disappears after the Pager. If you install it in the controller, everything is fine. BUT elsewhere, setting variables in the template works fine (even with Pager)
Steps to Reproduce
<?php
// init $model->paginate() in Controller
$this->setVar('title', 'New title');
echo $this->extend('_layout/backend');
?>
<?= $this->section('content') ?>
<table class="table text-center">
...
</table>
<?php dd($this, 'first') ?>
<?= $pager->links('default'); ?>
<?php dd($this, 'second') ?>
<?= $this->endSection() ?>
In first dump N variables, in second N-1 vars (unset “title”)
Expected Output
I looked into the system Pager file. It calls $this->view->setVar(‘pager’, $pager)->render(…) Probably this call interrupts the previous template code?
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (15 by maintainers)
That is confusing, but
$someModel->pager
and$pager
in the Pager template are different class instances. The$pager
in the template knows all about itself, so it does not take thegroup
parameter.See https://codeigniter4.github.io/CodeIgniter4/libraries/pagination.html#getcurrentpagenumber