问题
Google, as well as Symfony Docs and Cookbook haven't helped.
Let's say we have a website called http://www.example.com
that is running on Symfony2 and we are using an external FAQ and Support Service (for whatever reason) located at http://example.externalservice.com
.
We now thought it would be a suitable solution to create a route that points to the external FAQ service which would result in something like that:
# ../config/routing.yml
[...]
info.faq:
url: http://example.externalservice.com # Surely isn't working
[...]
This, because there could be a need to replace the support service with a home-brewed solution located within the application in the medium term. This route is used on various pages, so hardcoding or replacing them all when the support service changes is not an option.
So, my questions are:
- Is this the right approach or should we be using a TWIG extension and a parmeter located either in
parameters.yml
orconfig.yml
? - If it is the right approach, is it possible to create such a route without modifying the routing component itself?
Thank you in advance.
回答1:
In your parameters.yml add
external_url: http://example.externalservice.com
then in your controller :
$url = $this->container->getParameter('external_url');
return $this->redirect($url);
回答2:
From the Symfony2 documentation:
root:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: http://www.google.fr
permanent: true
For more informations about redirection, read the documentation below:
How to configure a redirect to another route without a custom controller
来源:https://stackoverflow.com/questions/17214438/is-it-possible-to-create-a-route-that-points-to-an-absolute-external-url