Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created June 2, 2012 03:28
Show Gist options
  • Save coreymcmahon/2856392 to your computer and use it in GitHub Desktop.
Save coreymcmahon/2856392 to your computer and use it in GitHub Desktop.
Using the Symfony 2 Routing component to match URLs - http://www.symfonycentral.com
<?php
// ...
/* Define the routes for our application */
$routes = new Routing\RouteCollection();
$routes->add('hello', new Routing\Route('/hello/{name}', array('name' => 'World')));
$routes->add('bye', new Routing\Route('/bye'));
/* Set up the context and establish whether this request matches a route */
$context = new Routing\RequestContext();
$context->fromRequest($request);
$matcher = new Routing\Matcher\UrlMatcher($routes, $context);
$match = $matcher->match($request->getPathInfo();
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment