Closed mbamber1986 closed 3 weeks ago
Just a quick follow up the my post request Actually passes through just seems to be query stings, im assuming this is because you can pass the Query string into the url with the router anyway hope to hear from you soon
Hi @mbamber1986, you get query strings in your controllers using:
$request->getQueryParams();
I can do that if the path is / but anything after that it doesn't display.
Is there something in doing wrong?
My aim was to pass query strings on specific paths, not a major issue
ie /users/login?attempt=1 2 3 etc of 3 lock account.
really my end goal was api request but i can probably pass them through the router {param1} options
Using the latest verison of PhpRouter.
<?php
require "../vendor/autoload.php";
class MyController
{
public function page(\Laminas\Diactoros\ServerRequest $request)
{
return json_encode($request->getQueryParams());
}
}
$r = \MiladRahimi\PhpRouter\Router::create();
$r->get('/', function () { return 'home'; });
$r->get('/page', [MyController::class, 'page']);
$r->dispatch();
And run using:
php -S localhost:4242
Worked as shown the image below.
Hi, i havent made an issue in a while however i have come across a wierd bug and hoping you can possibly assist or fix it.
the issue im having is i have created a custom requests class which works without the router in place however when i use the router and try and load my request class it doesnt display unless the root path is /
for example if i use /users/?username=martin : this displays nothing
where as if i make the url /?username=martin it outputs the value of $username
is this normal behaviour or does it need fixing.