How to accept any character in a url
Notice: This thread is very old.
- netteman
- Member | 125
Hi
I want to get urls in this format “www.example.com/info/123-any-characters”
and this code works (the string after the integer id can be anything, the presenter uses only the id)
public static function createRouter()
{
$router = new RouteList;
$router[] = new Route('info/<id [0-9]+>-[<anything>]', 'Info:default');
$router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');
return $router;
}
Could you tell me how to set that the compulsory id can be followed by any combination of characters? I used [<anything>] but I guess there is another way.
Thx :)
- dkorpar
- Member | 136
Easy solution would be to have
$router[] = new Route(‘info/<id>/<anything>]’,
‘Info:default’);
and then InfoPresenter::renderDefault function to actually receive ($id,$anything)
To have it like this you'll probably end up in writing your own Route
class
and that is actually really simple, it just have to implement
\Nette\Application\IRouter interface.
Last edited by dkorpar (2016-11-19 12:51)