Request To Mvc\Url use params
Phalcon\Mvc\Url
Generate a URL with GET arguments (/show/products?id=1&name=Carrots)
echo $url->get("show/products", ["id" => 1,"name" => "Carrots",]);
In the documentation i did not find anything about pass an array [$param1,$param2] that match with a Action. Has some way to do it withou extend the interface?
I think can has a flag or if the key isnt numeric
! count(array_filter(array_keys($args), 'is_string')) > 0
Has some way to it be a native component or some flag to modify the behavior. Maybe another method
$url->getWithParams('/url',[$param1,$param2....]);
matchs Show::Products($param1,$param2)
If i use ?id=1 does not match with param1
Hi,
Try this approach:
$router = $di->getRouter(); /* @var $router \Phalcon\Mvc\Router */
// Define your routes here
$route = $router->add("/test/(\??){params:[\&\?0-9a-zA-Z\=]+}",
[
"controller" => "index",
"action" => "test",
]
); /* @var $route Phalcon\Mvc\Router\Route */
$route->convert(
'params',
function ($params) {
// Transform the params
$array = [];
parse_str($params, $array);
return "{$array['id']}/{$array['name']}";
}
);
$router->handle();
params passed as "something/else" are matched to someAction($something, $else)
Hope it helps xD
The url generator does not support query parameters since it does not know about them. It goes by your route definition
example
$router->AddGet("/user/:id/:action", ["controller"=>"user", "action"=>2, "id" => 1])
->setName("user-action");
$url->get("user-action", ["action" => "edit", "id" => 2]);
should generate something long
http://www.site.com/user/2/edit
Thanks guys, i did mean something else, whithout a router use. but it's fine!