Skip to content

[RFC][Routing] Be able to alias routes #7055

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
wouterj opened this issue Feb 12, 2013 · 7 comments
Closed

[RFC][Routing] Be able to alias routes #7055

wouterj opened this issue Feb 12, 2013 · 7 comments
Labels

Comments

@wouterj
Copy link
Member

wouterj commented Feb 12, 2013

I would like to see an alias feature in the Routing component.

Usage

If you have a project and you use the SonataAdminBundle, the dashboard is at /admin/dashboard. I don't like that and want to use /admin. If we have an alias feature, we can do something like this:

admin_dashboard:
    path: /admin
    alias: sonata_admin_dashboard

We can even bring it a step further and say that an alias will copy all route data in the new one and you can override very thing. That means we can do something like this:

route_1:
    path: /post/{year}/{slug}
    defaults: { _controller: ... }
    requirements:
        year: \d{4}
        slug: \w+

route_2:
    requirements:
        year: \d{2, 4}
        slug: [0-9a-zA-Z]+

What do you guys think of this new feature? If the reaction is positive, I will start looking at how to implement this in the Routing component.

@Tobion
Copy link
Contributor

Tobion commented Feb 12, 2013

There was already an alias feature suggestion which was declined.
Why don't you simply override sonata_admin_dashboard directly in your routing file with the path you want? No need to alias it.

@wouterj
Copy link
Member Author

wouterj commented Feb 12, 2013

Yes, I have seen that issue (#6088) but that wasn't about overriden methods, that was just about renaming routes.

Why don't you simply override sonata_admin_dashboard directly in your routing file with the path you want?

Can I do that without using the defaults._controller option? I don't like it to use vendor logical controller names in the global routing file.

@Tobion
Copy link
Contributor

Tobion commented Mar 7, 2013

I still think aliasing is bad. For one thing, you then have 2 routes for the same thing. E.g. admin_dashboard and sonata_admin_dashboard in your above example. And you will have inconsistent paths, as the overridden route by the third party bundle would still be generated with the old path and your new definition would be used in your code when generating urls.

A probably better alternative would be to use the concept of extension. E.g.

sonata_admin_dashboard:
    path: /admin
    extends: true

In this case the route with the same name is not completely redefined, but instead it will reuse a route with the same name that was defined previously and only change the overriden options. It would be fairly easy to implement in the loader. On top of it one could allow defining the route name that one wants to extend (extends: base_route) which would basically add an alias feature. But as said above, not sure if this is a good thing.

@jfsimon
Copy link
Contributor

jfsimon commented Jul 16, 2013

@wouterj @fabpot what do you think of this?

@wouterj
Copy link
Member Author

wouterj commented Jul 31, 2013

@jfsimon I'm 👍

@fabpot
Copy link
Member

fabpot commented Jul 31, 2013

I'm not convinced that the extend mechanism is a good thing either. But if the patch is small enough, and if it does not introduce side effects, that might be something that we can add. Not a top priority tough.

@fabpot
Copy link
Member

fabpot commented Apr 28, 2014

Closing as it will probably bring more confusion than anything else (see #6088.)

@fabpot fabpot closed this as completed Apr 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants