Skip to content

Pager does not remove queryString from uri when pager is set to work on segments #8698

Description

@crustamet

Basically i've set up the pager to work on segments.

but the pages actually retain queryString from uri if i go to

https://example.com/blog/2?page=2

When the PagerRenderer kicks in it should remove ?page=2 from the query string when recreating the pager links

https://github.com/codeigniter4/CodeIgniter4/blob/develop/system/Pager/PagerRenderer.php#L265
I have changed this function like this

    public function links(): array
    {
        $links = [];

        $uri = clone $this->uri;

        for ($i = $this->first; $i <= $this->last; $i++) {
            $uri     = $this->segment === 0 ? $uri->addQuery($this->pageSelector, $i) : $uri->setSegment($this->segment, $i);
            $links[] = [
                'uri' => URI::createURIString(
                    $uri->getScheme(),
                    $uri->getAuthority(),
                    $uri->getPath(),
                    $uri->getQuery(['except' => ['page']]), // actualy it should only retain queryString that is not page
                    $uri->getFragment()
                ),
                'title'  => $i,
                'active' => ($i === $this->current),
            ];
        }

        return $links;
    }

But this implementation approach should only work when pager is set up on segments instead of query string.
This works for me for now but when I switch back to using the pager as before, for sure with this approach will not work.

My Feature request is to add this option to the Pager Config

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions