What is the difference between 'url' and 'path' in symfony2.3

后端 未结 2 1114
眼角桃花
眼角桃花 2021-02-01 15:13

The document said

{# src/Acme/ArticleBundle/Resources/views/Article/recentList.html.twig #}
{% for article in articles %}
    

        
相关标签:
2条回答
  • 2021-02-01 15:51

    They are very similar.

    path()

    Generates a relative/absolute path :

    path('contact') will generate /contact

    url()

    Generates a scheme-relative/absolute url, ie domain + path

    url('contact') will generate http://example.org/contact

    The url() style is useful when using cross-domain ajax or generating emails, because the hostname won't be the same.

    Take a look at the code https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php for more information

    0 讨论(0)
  • 2021-02-01 16:04

    url Twig function generates absolute path path Twig function generates / related url

    Example we have http://sf2sandbox.local with AcmeDemoBundle

    {{ path('_welcome') }} produce /
    {{ url('_welcome') }} produce http://sf2sandbox.local/
    
    0 讨论(0)
提交回复
热议问题