Reputation: 99523
I recently started using Silex. I have been grouping certain functionality of my application in a separate ControllerProviderInterace (such as putting login and register together).
My issue is that these ControllerProviders are 'mounted' under a sub-url, such as:
$app->mount('/account', new Controller\Account() );
How would I 'alias', rewrite, or map certain urls to other urls. For instance, I would like the following mapping:
/login -> /account/login
Upvotes: 1
Views: 1901
Reputation: 502
I don't know if the ship has sailed on this, but you can mount right under the root. For example...
$app->mount('/', new AuthenticationControllerProvider());
Then in AuthenticationControllerProvider, you can specify the routes:
$app->get('/login', function () use ($app) {
// do login things
});
$app->get('/register', function () use ($app) {
// do register things
});
If you wanted other routes to point to those you could set up routes that redirect with 301 to these.
I hope this helps!
Upvotes: 1
Reputation: 28249
You could do something like this:
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
$app->match('/login', function (Request $request) use ($app) {
$subRequest = $request->duplicate(null, null, null, null, null, array('REQUEST_URI' => '/account/login'));
return $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
});
I haven't actually tested this, so you may have to adjust it. But that's the approach I would take. Basically a forwarding controller.
Upvotes: 5