[BUG] Dispatcher get invalid params / Router issue
Hello. I found bug with using router with integer parameters (that should not be changed).
My $router contain rule:
$router->add
(
'/video_news/all/page/{page:[0-9]+}/category/{category:[0-9]+}/interval/{interval:[0-9]+}/sortby/{sortby:(hits|comments|date)+}',
[
'controller' => 'page',
'action' => 'build',
'lang_switcher' => 1, // this parameter should not be changed !!!
'media_type' => 3, // this parameter should not be changed !!!
'module_id' => 8, // this parameter should not be changed !!!
]
);
And PageController.php is
class PageController extends Phalcon\Mvc\Controller
{
public function buildAction()
{
print_r($this->dispatcher->getParams());
die();
}
}
At URL /video_news/all/page/30/category/0/interval/5/sortby/date I get output:
Array
(
[lang_switcher] => 30 // THIS IS INVALID !!!
[media_type] => 5 // THIS IS INVALID !!!
[module_id] => 8
[page] => 30
[category] => 0
[interval] => 5
[sortby] => date
)
You can see, that params lang_switcher and media_type is invalid!
Phalcon v1.0.0, FreeBSD
It's not a bug
/video_news/all/page/{page:[0-9]+}/category/{category:[0-9]+}/interval/{interval:[0-9]+}/sortby/{sortby:(hits|comments|date)+}
↑ 1 (lang_switcher) ↑ 2 ↑ 3 (media_type) ↑ 4 ↑ 5
It's not a bug
OK, maybe, but I need some params for route rule that should not change. How can I do this?
I think this is the only solution if you need default numeric params (which overrides the path params)
$router->add
(
'/video_news/all/page/{page:[0-9]+}/category/{category:[0-9]+}/interval/{interval:[0-9]+}/sortby/{sortby:(hits|comments|date)+}',
[
'controller' => 'page',
'action' => 'build',
'lang_switcher' => 1, // this parameter should not be changed !!!
'media_type' => 3, // this parameter should not be changed !!!
'module_id' => 8, // this parameter should not be changed !!!
]
)
->convert('lang_switcher', function($param){return 1;})
->convert('media_type', function($param){return 3;})
->convert('module_id', function($param){return 8;});
$router->handle('/video_news/all/page/30/category/0/interval/5/sortby/date');
print_r($router->getParams());
Array
(
[lang_switcher] => 1
[media_type] => 3
[module_id] => 8
[page] => 30
[category] => 0
[interval] => 5
[sortby] => date
)
I think this is the only solution if you need default numeric params
OK, I do that. Thank you very much.