Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

twig

symfony

The document said

{# 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 %} 

also, can use 'url' like this:

<a href="{{ url('_welcome') }}">Home</a> 

it confused me what is the difference between using 'url' and 'path'?

like image 361
RedWood Avatar asked Dec 05 '13 06:12

RedWood


1 Answers

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

like image 63
paxal Avatar answered Sep 20 '22 09:09

paxal