krishna
krishna

Reputation: 3647

Equivalent of Symfony 2's path() or url() in Symfony 1.4

Is there an equivalent of Symfony 2's path() or url() in Symfony 1.4, where you could use the name of the route (in the routing.yml) in the template to get the associated url

Upvotes: 1

Views: 1901

Answers (1)

JamesHalsall
JamesHalsall

Reputation: 13485

In Symfony 1.4 you can use the url_for() and link_to() helper functions. Using a combination of the two you can use route names to generate URLs quite easily...

Example usage:

Symfony2:

<a href="{{ path('welcome') }}">Home</a>

Symfony 1.4:

<a href="<?php echo url_for('@welcome');?>">Home</a>

A slightly more complication example:

Symfony2:

<a href="{{ path('blog_show', { 'slug': blog.slug }) }}">View Blog Post</a>

Symfony 1.4:

<?php echo link_to('View Blog Post', '@blog_show', array('slug' => $blog->getSlug()); ?>

Upvotes: 7

Related Questions