1

I'm porting a legacy system that uses Symfony framework. I have almost no experience on Symfony at all.

I need to overwrite a route to an action to an external site and including a session value as a parameter.

This is the current routing.yml code

mysystemtool:
  url:   /:module/mysystemtool/tool/*
  param: { action: mysystemtool }

And I need to redirect to a url like http://thirdpartyurl.com/?session_param=session_value

Any idea how to do this?

Martin
  • 11,216
  • 23
  • 83
  • 140
  • Which Symfony version? Legacy suggests 1.x, however, it's always more safe you name it. – hakre Jul 09 '12 at 22:55
  • I'm not sure I understand. Routing is for mapping incoming URI's to a controller/action. If you need to generate external URL's then you'll need your own logic/methods as this is outside the scope of the routing component. – MDrollette Jul 09 '12 at 22:56

1 Answers1

10

You cant route it perse becuase routing is only for internal stuff. That said you can redirect in the controller:

public function executeMysystemtool(sfWebRequest $request) {

    $param = $this->getUser()->getAttribute('session_param', 'default_value');
    $this->redirect('http://thirdpartyurl.com?session_param='.$param);
}

Of course you need your actions.class.php set up in a module so that you can code this action but if its an existing action then you should just have to change the logic in the action.

prodigitalson
  • 60,050
  • 10
  • 100
  • 114
  • The brilliant thing about this is that it also works for internal stuff when you don't want Symfony to mess with the URL. For instance in http://stackoverflow.com/questions/1496975/symfony-redirect-with-2-parameters if you don't want all GET parameters to be /stacked/into/slashes/like/that – user14764 Oct 28 '14 at 08:42
  • @user14764: Well in that case you can also change the routing rules to append extra parameters as a query string :-) – prodigitalson Jun 02 '15 at 15:31