Andrew Battye Andrew Battye - 2 months ago 10x
PHP Question

Symfony2 - routing to a fragment identifier

Is there a way to use the Symfony2 router to build URIs that include fragment identifiers?

We have a page listing lots of different entities (call this the "list" page) - when a user clicks on a link within one of the entity's details, they are taken to an "edit" page for that entity. When they click "save", we want them to return to the "list" page but with the entity they have just editing being visible. We have put each entity into a div with its unique identifier as the id, so what we need is for the controller that handles the updating of the entity take the user to something like;

where 12345 is the id of the entity they've just edited and is also the id of the div containing details of that same entity on the "list" page.

Of course, we could just get the url of the "list" page from the router, and then stick a hash and the entity id on the end, but this doesn't seem very elegant.


Just appending the hash to the end of the URL is the correct way to do it. Keep in mind that URL hashes are a purely client-side feature. There are no server-side functions to handle or generate them, because the server never needs to handle them.

It's something you'd normally just put into the view:

<a href="{{ path('my_list') }}#{{ }}">Link</a>