symfony-docs icon indicating copy to clipboard operation
symfony-docs copied to clipboard

[Routing] Add `{foo:bar}` syntax to define a mapping between a route parameter and its corresponding request attribute

Open alamirault opened this issue 1 year ago • 3 comments

Fix https://github.com/symfony/symfony-docs/issues/19846

alamirault avatar May 07 '24 13:05 alamirault

I did not find any example on map entity, you may consider this example below

    #[Route(path: '/profile/{name:name}/{age:age}', name: 'profile', methods: ['GET'])]
    public function fetchProfile(Profile $profile): Response
    {
       // 

    }

rcsofttech85 avatar May 08 '24 16:05 rcsofttech85

I did not find any example on map entity, you may consider this example below

    #[Route(path: '/profile/{name:name}/{age:age}', name: 'profile', methods: ['GET'])]
    public function fetchProfile(Profile $profile): Response
    {
       // 

    }

I'm not sure to understand your suggestion, why map name to name and age to age ?

I think the original PR has no direct link with MapEntity ?

alamirault avatar May 09 '24 18:05 alamirault

@alamirault The main idea was to improve automapping doctrine entities. Now, automapping of entities in favor of mapped route parameters is deprecated. The code I posted is a working example of entities and route parameters.

{name:name}/{age:age} = > "foo" is the name of the wildcard and "bar" is a property or attribute of the entity.

Here is another simple example:

    #[Route(path: '/product/{product_slug:slug}', name: 'product', methods: ['GET'])]
    public function getProduct(Product $product): Response
    {
       // 

    }

@nicolas-grekas could you please ensure it's correct.

rcsofttech85 avatar May 10 '24 01:05 rcsofttech85