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

[Routing] Allow ArrayAccess object as parameter #5999

Closed
franzliedke opened this issue Nov 13, 2012 · 3 comments
Closed

[Routing] Allow ArrayAccess object as parameter #5999

franzliedke opened this issue Nov 13, 2012 · 3 comments
Labels

Comments

@franzliedke
Copy link
Contributor

When generating URLs, named parameters are usually passed like this:

$uri = $router->generate('blog_show', array('slug' => 'my-blog-post'));

It would be cool if one could pass an object that implements the ArrayAccess interface, too. That would make generating routes for models incredibly easy (and allow for changing the URL parameters without changing the places where the URLs are generated).

Something like this:

$uri = $router->generate('blog_show', $post);

Quite possibly the current implementation loops through the array and then tries to replace the appropriate placeholder if it exists. For this to work, that implementation would obviously have to be reversed - take the route, search for placeholders and then look for the corresponding parameters.


Not sure, maybe this is already possible, I wasn't very successful digging through the code.

@Tobion
Copy link
Member

Tobion commented Jan 8, 2013

Your feature idea is right and it was intented to support using objects as parameter (object routes) from the beginning. We just need a common approach to it. But you suggestion using ArrayAccess is only half of a solution because you would not be able to add extra paramters that are not placeholders to the query string anymore.
So instead we should define an interface like Routable that defines getParameters which objects must implement to expose their parameters.

@Tobion
Copy link
Member

Tobion commented Jan 8, 2013

See also #2288

@Tobion
Copy link
Member

Tobion commented Jan 16, 2015

Closing as duplicate of #10395

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

2 participants