Skip to content

Instantly share code, notes, and snippets.

@serapheem
Created July 21, 2013 04:41
Show Gist options
  • Select an option

  • Save serapheem/6047504 to your computer and use it in GitHub Desktop.

Select an option

Save serapheem/6047504 to your computer and use it in GitHub Desktop.
Symfony2 - Generating and matching routes
<?php
$params = $router->match('/blog/my-blog-post');
// array('slug' => 'my-blog-post', '_controller' => 'AcmeBlogBundle:Blog:show')
$uri = $router->generate('blog_show', array('slug' => 'my-blog-post'));
// /blog/my-blog-post
?>
If the frontend of your application uses AJAX requests,
you might want to be able to generate URLs in JavaScript based on your routing configuration.
By using the FOSJsRoutingBundle, you can do exactly that:
var url = Routing.generate('blog_show', { "slug": 'my-blog-post'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment