Welcome Guest, Not a member yet? Register   Sign In
pagination adding params
#1

With codeigneter 4, can someone guide me to how to add additional parameters to links?
Reply
#2

What exactly are the parameters? QUERY_STRING /users/1000?option=full ?
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

(This post was last modified: 08-04-2024, 11:33 PM by cadgiru.)

(08-03-2024, 10:45 AM)ozornick Wrote: What exactly are the parameters? QUERY_STRING /users/1000?option=full ?

Tried building links with added parameters:

``` php
// Existing code setup
$data['body']['pagerLinks'] = $pager->makeLinks(
    $data['body']['page'],    // current page
    $data['body']['perPage'],  // items per page
    $data['body']['ant'],      // total items available
    'default_full',            // pagination template
    0,                        // segment number (assuming default or not needed)
    'page',                    // the URI segment that contains the page number
    true,                      // whether to keep query string
    ['a' => $data['body']['a'], 'b' => $data['body']['b']]    // array of additional query parameters to append
);
```

This gives no error, but additional params (a, b) are not added to links?
Do I need to modify template?
What am I doing wrong?
Reply
#4

(This post was last modified: 08-05-2024, 12:41 AM by kenjis.)

Quote:By default, all GET queries are shown in the pagination links.
See https://codeigniter.com/user_guide/libra...ed-queries

And you should read the docs carefully:
https://codeigniter.com/user_guide/libra...pagination
Reply
#5

(This post was last modified: 08-05-2024, 02:34 AM by cadgiru.)

(08-05-2024, 12:39 AM)kenjis Wrote:
Quote:By default, all GET queries are shown in the pagination links.
See https://codeigniter.com/user_guide/libra...ed-queries

And you should read the docs carefully:
https://codeigniter.com/user_guide/libra...l-paginati

being a newbe, I have tried what U suggested, redading docs carefully, but still at a loss...

What I am basically trying to achieve is building a url something like :

example.com/myview.php?a=1234&b=5678&page=4

Feel I am going in circles, as always 'the devil is in the detail'
Reply
#6

1. You need to use the method correctly. If you specify incorrect parameters, it does now work as you expected.
2. Try the sample code in the User Guide to understand how the code works.
3. By default, all GET queries are shown in the pagination links. So you don't need to do an extra work.

PHP Code:
        $pager service('pager');

        $page    = (int) ($this->request->getGet('page') ?? 1);
        $perPage 20;
        $total  200;

        // Call makeLinks() to make pagination links.
        $pager_links $pager->makeLinks($page$perPage$total);

        $data = [
            // ...
            'pager_links' => $pager_links,
        ];

        return view('users/index'$data); 
Reply
#7

(This post was last modified: 08-06-2024, 06:12 AM by cadgiru.)

(08-05-2024, 02:57 AM)kenjis Wrote: 1. You need to use the method correctly. If you specify incorrect parameters, it does now work as you expected.
2. Try the sample code in the User Guide to understand how the code works.
3. By default, all GET queries are shown in the pagination links. So you don't need to do an extra work.

PHP Code:
        $pager service('pager');

        $page    = (int) ($this->request->getGet('page') ?? 1);
        $perPage 20;
        $total  200;

        // Call makeLinks() to make pagination links.
        $pager_links $pager->makeLinks($page$perPage$total);

        $data = [
            // ...
            'pager_links' => $pager_links,
        ];

        return view('users/index'$data); 

3. By default, all GET queries are shown in the pagination links. So you don't need to do an extra work

What am I missing?
Really going in circles, what I want is to add two GET queries to pagination, resulting in something like: example.com/myview?a=1234&b=5678&page=4.
Am struggling to find how to add the GET queries.
Thx in advance, all help appreciated
Reply
#8

Try the sample code in the User Guide.
Reply
#9

(08-06-2024, 05:56 AM)cadgiru Wrote:
(08-05-2024, 02:57 AM)kenjis Wrote: 1. You need to use the method correctly. If you specify incorrect parameters, it does now work as you expected.
2. Try the sample code in the User Guide to understand how the code works.
3. By default, all GET queries are shown in the pagination links. So you don't need to do an extra work.

PHP Code:
        $pager service('pager');

        $page    = (int) ($this->request->getGet('page') ?? 1);
        $perPage 20;
        $total  200;

        // Call makeLinks() to make pagination links.
        $pager_links $pager->makeLinks($page$perPage$total);

        $data = [
            // ...
            'pager_links' => $pager_links,
        ];

        return view('users/index'$data); 

3. By default, all GET queries are shown in the pagination links. So you don't need to do an extra work

What am I missing?
Really going in circles, what I want is to add two GET queries to pagination, resulting in something like:  example.com/myview?a=1234&b=5678&page=4.
Am struggling to find how to add the GET queries.
Thx in advance, all help appreciated
@kenjis  thx for Your persistence in trying to guide me in the right direction. Sadly I still must have missed something
Reply




Theme © iAndrew 2016 - Forum software by © MyBB