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

Obtaining QueryString Data #35

Closed
mbamber1986 opened this issue Mar 8, 2021 · 5 comments
Closed

Obtaining QueryString Data #35

mbamber1986 opened this issue Mar 8, 2021 · 5 comments

Comments

@mbamber1986
Copy link

cant see it in your documentation but does the routing support using ?keyword=mike im trying to setup a search page for users and it doesnt seem to be picking up and results to the catch and gives my custom error page which is just page not found

my form path is : /admin/search and then as a get method throws up ?keyword=

my route at the moment as i thought it might work is /admin/search/?keywork={keyword}

tia

@miladrahimi
Copy link
Owner

miladrahimi commented Mar 12, 2021

Hello,
The ?keyword=mike and everything after ? is called Query String and is not part of the route.
As for your search route /admin/search?keywork={keyword}, the route should be /admin/search and it can be mapped to controller like SearchController::index().
To catch the query string (keywork={keyword}) you can do something like the following code:

use Laminas\Diactoros\ServerRequest;

class SearchController {
    function index(ServerRequest $request) {
        $keyword = $request->getQueryParams()['keyword'];
        // Search $keyword in database or anywhere else...
        // return response as view or json, etc.
    }
}

@mbamber1986
Copy link
Author

mbamber1986 commented Mar 12, 2021 via email

@mbamber1986
Copy link
Author

mbamber1986 commented Jan 7, 2023

Hi So as of now i am still using your Router ive been out of it for a while however it seems that $keyword = $request->getQueryParams()['keyword']; this no longer works ansd gives Undefined array key "id" , i have changed the word keyword to id.

i have tried wrapping it in an iseset and nothing seems to be changing has something changed on yours or laminas side for this to not work anymore

@mbamber1986 mbamber1986 changed the title Question Getting Url via Querystring Jan 7, 2023
@mbamber1986 mbamber1986 changed the title Getting Url via Querystring Obtaining QueryString Data Jan 7, 2023
@miladrahimi
Copy link
Owner

what do u get when print_r($request->getQueryParams()) ?

@mbamber1986
Copy link
Author

image

heres the address bar snippet
image

and my code

image

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