Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pager with search queries #950

Closed
natanfelles opened this issue Feb 25, 2018 · 2 comments
Closed

Pager with search queries #950

natanfelles opened this issue Feb 25, 2018 · 2 comments

Comments

@natanfelles
Copy link
Contributor

I'm trying to paginate model results by a GET query:

On the first search the URI is:

/search?q=you+alice+to+the+little

When clicked to the page 2 in the link generated by the Pager of Model paginate(), it becomes:

/search?q=you%2Balice%2Bto%2Bthe%2Blittle&page=2

Going to the third page, it becomes:

/search?q=you%252Balice%252Bto%252Bthe%252Blittle&page=3

I was able to manipulate the string to get the data in the database with:

$search = $this->request->getGet('q');
$search = urldecode($search);
$search = str_replace('+', ' ', $search);
var_dump($search);exit;

Then all inputs will return the same string: 'you alice to the little'.

This issue is related to the pagination links, that every time encode the, already encoded, query string.

On page 5 it becomes:

/search?q=you%25252Balice%25252Bto%25252Bthe%25252Blittle&page=5

On page 6:

/search?q=you%2525252Balice%2525252Bto%2525252Bthe%2525252Blittle&page=6

I tried to manipulate it with:

$search = str_replace('%2B', ' ', $search);
$search = str_replace('%252B', ' ', $search);

But as the page number increases the URI is re-encoded and a new override is needed to keep the original string.

I would open this question in the forum, but I think it is more related to how pagination works at the moment.

Thanks.

@natanfelles
Copy link
Contributor Author

natanfelles commented Feb 25, 2018

Oh, solved here. Explicitly changing the $_GET['q'] before call the model paginate solved it:

$search = $this->request->getGet('q');
$search = urldecode($search);
//$search = str_replace('+', ' ', $search);
$_GET['q'] = $search;
$_GET      = array_intersect_key($_GET, ['q' => '', 'page' => '']);

I'll leave the issue open if you want to analyze more. Thank you.

@lonnieezell
Copy link
Member

Yes, urlencoding was backed into the URI component to meet RFC 3986. However, you're the second person that mentioned confusion about it so I did a bit more digging around tonight. It appears there are times when at least Apache will already take care of URL-encodeing and decoding behind the scenes, so I'm thinking it might be smart to remove that feature and leave it to developers to encode if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants