且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

symfony2.3中的'url'和'path'有什么区别

更新时间:2023-11-19 21:20:28

它们非常相似.

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

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