问题描述
文件说
{# src/Acme/ArticleBundle/Resources/views/Article/recentList.html.twig #}
{% for article in articles %}
<a href="{{ path('article_show', {'slug': article.slug}) }}">
{{ article.title }}
</a>
{% endfor %}
也可以像这样使用url":
also, can use 'url' like this:
<a href="{{ url('_welcome') }}">Home</a>
它让我感到困惑,使用url"和path"有什么区别?
it confused me what is the difference between using 'url' and 'path'?
推荐答案
它们非常相似.
生成相对/绝对路径:
path('contact')
将生成 /contact
生成scheme-relative/absolute url,即域+路径
Generates a scheme-relative/absolute url, ie domain + path
url('contact')
将生成 http://example.org/contact
url() 样式在使用跨域 ajax 或生成电子邮件时很有用,因为主机名不会相同.
The url() style is useful when using cross-domain ajax or generating emails, because the hostname won't be the same.
看一下代码https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php 了解更多信息
Take a look at the code https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php for more information
这篇关于symfony2.3中'url'和'path'有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!