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
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()); ?>
2 Comments
krishna
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.
VanTanev
What you're interested in is the no_script_name option in apps/appname/config/settings.yml.