1

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

1 Answer 1

7

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()); ?>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, when I do url_for('@route_name'); , the url has index.php added to it (like xxxx.com/index.php/<route_name_path>). Do you know why the index.php shows up ? and how can I suppress that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.