We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Router returns notFound when using query parameters

I have a simple router config in Phalcon 4.0:

use Phalcon\Mvc\Router;
$router = new Router(false);
$router->notFound(['controller' => 'Http', 'action' => 'code404']);
$router->add('/', ['controller' => 'index', 'action' => 'index']);

https://my.domain/ returns something from index controller. But when i add even symbol '?' to my url (https://my.domain/?), it returns 404 page. I can't get what should i change in route and didn't found any information about routing query parameters in documentation.

P.S. I debugged $_GET when using any parameters, they are present.

hmmm looks like a bug. Create an issue



2.0k
edited May '19

The problem is in request URI. In documentation we see start app example like this code: $response = $application->handle($_SERVER["REQUEST_URI"]);

but when we send query parameters, for example /some/script.php?foo=bar,

variable $_SERVER["REQUEST_URI"] contains /some/script.php?foo=bar,

variable $_SERVER["QUERY_STRING"] contains _url=/some/script.php&foo=bar,

variable $_GET["_url"] contains /some/script.php, and variable $_GET["foo"] contains bar, as needed.

I have changed handler URI to $_GET['_url'] and it works now as expected.

So i would call it a documentation bug :) Or maybe it is all the same router bug that should be fixed in next versions.