I want to generate a url like ../profile/firstname.lastname
But i don't understand how i can do this because i want in my php also the id from the user.
this is my controller:
$controllers
->match('profile/{firstname.lastname}/', array($this, 'profile'))
->assert('userId', '\d+')
->method('GET|POST')
->before(array($this, 'checkLogin'))
->bind('home.profile');
You have to build your Route
like this
<route id="profile" path="/profile/{first_name}.{last_name}">
<default key="_controller">...</default>
</route>
And in controller create like this
$this->generateUrl('profile', [ 'first_name' => 'skowron', 'last_name' => 'line' ]);
but if you have 2 profiles with this same data it will give you bad results. Then you can create slug or add id
parameter to your route
Symfony uses Symfony\Component\Routing\Generator\UrlGenerator::generate() to generate paths. But probably the path is not defined in your routing system. So you must create an instance of it and pass a RouteCollection
which only contains tha path you want and it does not seem to be a good method.
It's better to use preg_replace.