Skip to content

Instantly share code, notes, and snippets.

@michalpipa
Created December 21, 2011 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michalpipa/1507820 to your computer and use it in GitHub Desktop.
Save michalpipa/1507820 to your computer and use it in GitHub Desktop.
Symfony2 router for PHP 5.4 build-in web server
<?php
if (isset($_SERVER['SCRIPT_FILENAME'])) {
return false;
} else {
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT']
. DIRECTORY_SEPARATOR
. 'app.php'
;
require 'app.php';
}
@lolautruche
Copy link

To work properly and make Symfony being able to proper URLs, you need to set $_SERVER['SCRIPT_FILENAME'] to app.php (or better : app_dev.php). Otherwise you might have double slashes in generated URLs.

<?php
if (isset($_SERVER['SCRIPT_FILENAME']))
{
    return false;
}
else
{
    $appScript = 'app_dev.php';
    $_SERVER['SCRIPT_FILENAME'] = $appScript;
    require $appScript;
}

@michalpipa
Copy link
Author

Thank you Jérôme. I've actually done this in my pull request: symfony/symfony#3465

Sample router is updated now

@lolautruche
Copy link

Nice ! This would be a really nice addition to Symfony indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment