8000 Passing objects to Route generator · Issue #10395 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Passing objects to Route generator #10395

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

Closed
nick4fake opened this issue Mar 6, 2014 · 15 comments
Closed

Passing objects to Route generator #10395

nick4fake opened this issue Mar 6, 2014 · 15 comments
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Routing

Comments

@nick4fake
Copy link

For Symfony2 Router with the help of standart bundle (sensio extra) we can write ParamConverters to convert request param=>object. Is there any standart way to use reversed convertion?

Now we must do something like this:
path('DevBlogBundle_post_show',{'post':post.id})
While a better way would be:
path('DevBlogBundle_post_show',{'post':post})

I've found even example jist:
https://gist.github.com/stevelacey/3226510

  1. Maybe, we should think about adding such functionality to future releases of, for example, sensioFrameworkExtra bundle?
  2. If there is no such functionality, is bundle providing such extension would be needed?

Thanks.

@nick4fake
Copy link
Author

Possibe way might be creating something like ReverseParamConverter annotation to convert arguments to route.

@Baachi
Copy link
Contributor
Baachi commented Mar 6, 2014

schmittjoh wrote a library which supports this behaviour
https://github.com/schmittjoh/object-routing

@nick4fake
Copy link
Author

Thanks a lot!
Exactly what I needed.

Thus another question: why this is not default functionality of Symfony2 standart or SensioExtraBundle?

@cordoval
Copy link
Contributor
cordoval commented Mar 6, 2014

nice idea, wonder if a cookbook would help? if so let's open a ticket in the docu 👶

@Baachi
Copy link
Contributor
Baachi commented Mar 6, 2014

@nick4fake I think this is to complex to implement it into core.

@nick4fake
Copy link
Author

@Baachi ,
http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html

SensioFrameworkExtra providers one-way converters. I think this is inconsistent.

@Baachi
Copy link
Contributor
Baachi commented Mar 6, 2014

Than submit a PR to add this feature 👍

@jakzal
Copy link
Contributor
jakzal commented Mar 11, 2014

re #2288 #5999

@linaori
Copy link
Contributor
linaori commented Aug 24, 2015

I wrote a bundle that does exactly this: https://github.com/iltar/http-bundle. There's no need for additional twig functions, custom routers or custom generators.

Please take a look and see if there's anything missing.

@javiereguiluz
Copy link
Member

In the past, I was 👍 about this feature ... but now I'm strongly 👎 . Why?

  • You write your templates once ... but execute them continuously. So the execution of templates must be fast, including URL generation.
  • All the proposed solutions hurt performance:
    • @iltar solution is valid, but a bit boring and verbose. You need to write resolvers for each object, etc.
    • If we use PropertyAccess to find the route attributes automagically from the passed objects, everything is automated, but it will seriously hurt performance.

So, not using objects and passing the routes attributes individually is not bad at all to me. I recommend to close this proposal as "won't fix". Thanks!

@linaori
Copy link
Contributor
linaori commented Aug 4, 2017

You need to write resolvers for each object, etc.

Small side note, I try to make things as little effort as possible, therefore things like entities are recognized and simply use the identifier value.

If we use PropertyAccess to find the route attributes automagically from the passed objects, everything is automated, but it will seriously hurt performance

My only concern with this, are batch jobs. You won't often create links with objects in them, so is this really overhead each request? Isn't the path it needs to take, cached as well?

@javiereguiluz
Copy link
Member

@iltar I'm still 👎 because this is being lazy once (when writing the route) and paying for it all your life (worse performance when generating URLs in templates).

@remi-blaise
Copy link
Contributor

@javiereguiluz Writing programs to save human's time by using machine's time... This is the goal of programming, and the goal of Symfony too! This seems not to be a valid argument as we do not generate so much routes. Moreover, we could do that in a way it will be fast to interprete. I particularly liked @ScreamingDev proposal.

@stof
Copy link
Member
stof commented Aug 17, 2017

@Zzortell we do not generate so much routes is a wrong assumption. I have cases generates thousands URLs in the page (and I know other peoples have such cases too, which is why we have a strong focus on performance for the Routing component, even though most recent improvements were on the matching side)

And @ScreamingDev's proposal in the issue you linked causes issues for matching (what would the request attribute look like after matching when the placeholder uses an object access syntax ?)

@nicolas-grekas
Copy link
Member

Closing here as it looks like we don't want this in core, and it's already doable in a bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Routing
Projects
None yet
Development

No branches or pull requests

9 participants
0