Symfony href应该适用于app_dev.php和app.php


Symfony href shoud work for app_dev.php and app.php

我在Twig中有一个链接:

链路

哪个输出为url:www.domain.com/category-lapops

但在dev上,我需要输出:www.domain.com/app_dev.php/category-laptops

这有什么作用吗?还是我应该根据环境自己写?

谢谢Nik

为此,您必须在分支模板中使用{{ 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')应该在两种环境中都为您提供正确的链接。