Search code examples
phpsilex

Silex internal redirect with URL change?


I'm using Silex and I'm trying to redirect from one to another route, but with changing URL. I've tried a few things so far.

1) Using Sub-Request, works but URL does not change.

2) Using Normal redirect works but the data is sensitive and i don't want to pass it to the client and then back if not needed.

-> $app->redirect($app['url_generator']->generate('route_name', array( 'data' => $dataArray )));

What i actually want is to internally redirect with some data. But the URL has to change.

My Routes look like this:

$app->match('/some/url/', 'Acme\\Controller\::someAction')
    ->bind('route_name');

How to do that in Silex?

And yes i know that Silex is in maintenance mode.


Solution

  • URL is a client side thing, if you wan't to change it you don't have the choice : you need to go back to client side.

    Have you considered to modify the URL after the response ? In javascript, you can modify the URL without reload the page :

    https://developer.mozilla.org/en-US/docs/Web/API/History_API

    https://stackoverflow.com/a/3354511/3139242