symfony2.3中的'url'和'path'有什么区别 [英] What is the difference between 'url' and 'path' in symfony2.3

查看:10
本文介绍了symfony2.3中的'url'和'path'有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件说

{# 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'?

推荐答案

它们非常相似.

生成一个相对/绝对的路径:

Generates a relative/absolute path :

path('contact') 会生成 /contact

生成方案相对/绝对的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'有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆