如何从Twig模板获取当前URL?
我使用的是带有PHP的Twig,没有任何其他框架。
发布于 2012-10-04 00:21:04
下面的代码可以在Silex中运行,当然也可以在Symfony2中运行,因为它们共享Request类(我没有测试过):
{{ app.request.getRequestUri() }}
发布于 2013-08-26 01:39:51
Go http://api.symfony.com/2.3/Symfony/Component/HttpFoundation/Request.html
或者:{{ app.request.getUri() }}
表示完整的Uri。
发布于 2012-03-30 22:54:10
在这里,我发现了一些东西,使它与sliex框架通用。我猜我的解决方案并不完美,但它已经完成了工作。
在PHP代码中添加以下代码:
$app = new Silex\Application();
// add the current url to the app object.
$app['current_url'] = $_SERVER['REQUEST_URI'];
然后,您可以在Twig模板中执行以下操作
{{ app.current_url }}
让我知道这个方法的本机行是什么。
https://stackoverflow.com/questions/9339370
复制相似问题