Welcome Guest, Not a member yet? Register   Sign In
Undefined variable $ inside template pagination
#1

(This post was last modified: 11-09-2023, 05:20 PM by rax.)

Hello all!
after upgrading from 4.2.2 to 4.4.3 and php7.4 to 8.2 my pagination template started to fail, isn't get some vars from controller, perhaps I missed something during upgrade and a little help can solve this issue.
Undefined variable $
----------
config/pager.php - OK
PHP Code:
public array $templates = [
'front_full'    => 'App\Views\layouts\custom_pagination',
]; 


Controllers/Main.php - OK
PHP Code:
public function pagination(){
        $this->data['page'] =  !empty($this->request->getVar('page')) ? $this->request->getVar('page') : 1;
        $this->data['perPage'] =  10;
return 
view('pages/list'$this->data);


/Views/pages/list.php - OK
PHP Code:
$pager->makeLinks($page$perPage'front_full'


/Views/layouts/custom_pagination.php- OK but don't receive $page or $perPage vars... -> Undefined variable $page and $perPage


Thank you for your support,
Reply
#2

Now Pager does not use the shared View instance.
See https://github.com/codeigniter4/CodeIgni...ssues/7703
Reply
#3

(This post was last modified: 11-10-2023, 02:18 AM by rax.)

(11-09-2023, 10:13 PM)kenjis Wrote: Now Pager does not use the shared View instance.
See https://github.com/codeigniter4/CodeIgni...ssues/7703

Thanks for your answer, I didn't saw any related info regarding that under: https://www.codeigniter.com/user_guide/i...ading.html or https://www.codeigniter.com/user_guide/l...ation.html ...

Does codeigniter4 provide that with some builtin function or we've to build it?

Regards,
Reply
#4

(This post was last modified: 11-10-2023, 03:17 AM by kenjis.)

It is a bug fix. No detailed info is documented in the user guide.

Why do you need these variables?
Can you get needed info from the $pager object?
Reply
#5

To display the number of records from tables in many pages without write the same code and html/css in every one.
Reply
#6

Use the Pager object instead of variables to Views.
https://github.com/codeigniter4/CodeIgni.../Pager.php
Reply
#7

(11-09-2023, 12:01 PM)rax Wrote: Hello all!
after upgrading from 4.2.2 to 4.4.3 and php7.4 to 8.2 my pagination template started to fail, isn't get some vars from controller, perhaps I missed something during upgrade and a little help can solve this issue.
Undefined variable $
----------
config/pager.php - OK
PHP Code:
public array $templates = [
'front_full'    => 'App\Views\layouts\custom_pagination',
]; 


Controllers/Main.php - OK
PHP Code:
public function pagination(){
        $this->data['page'] =  !empty($this->request->getVar('page')) ? $this->request->getVar('page') : 1;
        $this->data['perPage'] =  10;
return 
view('pages/list'$this->data);


/Views/pages/list.php - OK
PHP Code:
$pager->makeLinks($page$perPage'front_full'


/Views/layouts/custom_pagination.php- OK but don't receive $page or $perPage vars... -> Undefined variable $page and $perPage


Thank you for your support,
You can try:
<php $pager_inf = \Config\Services::pager()
$page = $pager_inf -> getCurrenPage();
$total = $pager_inf ->getTotal();
$perPage = $pager_inf->getPerPage();
?>
    }
    ?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB