Skip to main content

Anchor in URL when using Symfony"s redirect function


I'm using




$this->redirect('route', array('id' => $id));



but I need to be able to put "#" anchor at the end but I can't find a way of doing that. Any ideas?



The code




$this->redirect('route', array('id' => $id));



returns /route/id/5 but I want to be able to create /route/id/5#anchor7



EDIT - Solution found

Ok figured out a solution. Its working fine :)




$this->redirect($this->generateUrl('route', array('id' => $id)) . '#anchor7');



StackOverflow wouldn't let me post it as an answer since I'm a "new user" O_o


Source: Tips4allCCNA FINAL EXAM

Comments

  1. Your own answer:

    $this->redirect($this->generateUrl('route', array('id' => $id)) . '#anchor7');

    ReplyDelete
  2. not tested, but:

    $this->redirect('route', array('id' => ($id.'#anchor7'));

    Another (hacky) way:

    Add a field to your parameters, e.g. 'anchor' => 'anchor7' and on the target site, parse this parameter and use javascript to scroll to the anchor.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?