是否可以创建指向绝对外部URL的路由? [英] Is it possible to create a route that points to an absolute external URL?
问题描述
Google以及Symfony Docs和Cookbook都没有帮助。
Google, as well as Symfony Docs and Cookbook haven't helped.
假设我们有一个名为 http:// www的网站.example.com
在Symfony2上运行,我们正在使用位于 http://example.externalservice.com 的外部常见问题解答和支持服务(无论出于何种原因)
。
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
.
我们现在认为这是创建指向外部FAQ服务的路由的合适解决方案,该路由会导致类似以下情况:
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.
因此,我的问题是:
- 这是正确的方法还是我们应该使用TWIG扩展名和位于
parameters.yml $ c $中的参数c>或
config.yml
? - 如果是正确的方法,是否可以在不修改路由的情况下创建这样的路由
预先感谢您。
推荐答案
在您的parameter.yml中添加
In your parameters.yml add
external_url: http://example.externalservice.com
然后在您的控制器中:
$url = $this->container->getParameter('external_url');
return $this->redirect($url);
这篇关于是否可以创建指向绝对外部URL的路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!