I have a problem with PhalconPHP that it's driving me crazy.
I'm developing an API, the URL is: ..../api/users/getAll?user_id=1&email=aaa
This bring me to Controller: UsersController, and action: getAllAction($user_id, $email). (OK).
My beforeDispatch event, prepare action parameters:
// Attach a listener
$eventsManager->attach(
"dispatch:beforeDispatchLoop",
function (Event $event, $dispatcher) {
$request = new Request();
$params = $request->get();
$keyParams = [];
// Use odd parameters as keys and even as values
foreach ($params as $key => $value) {
if ($key == '_url') continue;
$keyParams[$key] = $value;
}
// Override parameters
$dispatcher->setParams($keyParams);
}
);
When I call URL in this order: URL?user_id=aa&email=bbb everything is OK, but when i call URL with inverted parameters, (URL?email=bbb&user_id=aaa), getAllAction matchs parameters wrongly.
Doubt: now action parameters are matching by position, but i need to change it by name.
It's posible?
PD: I don't want to use $request->getQuery or $request->get. I want to match dynamically by name.
Any idea?
Thank you!