Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping self url does not works #35

Open
regniblod opened this issue Jun 5, 2017 · 1 comment
Open

Mapping self url does not works #35

regniblod opened this issue Jun 5, 2017 · 1 comment

Comments

@regniblod
Copy link

I try to serialise an object but I get an error with the URL generation for the self url property.

This is my mapping:

mapping:
  class: AppBundle\User
  alias: User
  id_properties:
    - id
  urls:
    self: get_user

This is get_user route definition (which works if I call it directly):

@Route(
    path="/user/{id}",
    name="get_user",
    requirements={"id": "\d+"}
)

And this is the error I get:

Parameter "id" for route "get_user" must match "\d+" ("{id}" given) to generate a corresponding URL.

If I change the mapping to something like

# ...
  urls:
    self: route_without_parameters
# ...

I get a response but without any url referencing that route:

{
  "data": {
    "type": "user",
    "id": "1",
    "attributes": {
        ...
    }
  },
  "jsonapi": {
    "version": "1.0"
  }
}
@regniblod
Copy link
Author

Can be closed, if I change the requirements of the route to requirements={"{id}": "\d+"} (note the braces in the parameter name) it works.

I still don't know why Symfony allows both ways of defining requirements tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant