Symfony href 应该适用于 app_dev.php 和 app.php
Symfony href shoud work for app_dev.php and app.php
我在 Twig 中有一个 link:
link
输出为 url:www.domain.com/category-laptops
但是在 dev 上我需要输出:www.domain.com/app_dev.php/category-laptops
这个有什么功能吗,还是要根据环境自己写?
谢谢
尼克
你必须在你的树枝模板中使用 {{ path() }}
。
示例:
<a href="{{ path('article_show', {'slug': article.slug}) }}">
{{ article.title }}
</a>
参见:http://symfony.com/doc/current/reference/twig_reference.html#path
如果要使用绝对链接,可以使用{{ url() }}
代替{{ path() }}
参见:http://symfony.com/doc/current/reference/twig_reference.html#url
如果您已正确设置路线,那么 path('route_name')
应该会在两种环境中为您提供正确的 link。
我在 Twig 中有一个 link:
link
输出为 url:www.domain.com/category-laptops
但是在 dev 上我需要输出:www.domain.com/app_dev.php/category-laptops
这个有什么功能吗,还是要根据环境自己写?
谢谢 尼克
你必须在你的树枝模板中使用 {{ path() }}
。
示例:
<a href="{{ path('article_show', {'slug': article.slug}) }}">
{{ article.title }}
</a>
参见:http://symfony.com/doc/current/reference/twig_reference.html#path
如果要使用绝对链接,可以使用{{ url() }}
代替{{ path() }}
参见:http://symfony.com/doc/current/reference/twig_reference.html#url
如果您已正确设置路线,那么 path('route_name')
应该会在两种环境中为您提供正确的 link。