silex and the trailing slash

Wrong route definition: $app->get(‘/demo’, function() use($app) { return “demo”; }); Right route definition: $app->get(‘/demo/’, function() use($app) { return “demo”; }); The .htaccess file: <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f # RewriteRule ^ index.php [QSA,L] RewriteRule ^ index.php [QSA,L] </IfModule>  

Silex: routing to hostname

This is an example how to split your silex project by different hostnames. $app->get(‘/’, function(Request $request) use ($app) { return “foo.localhost.com”; })->host(“foo.localhost.com”); $app->get(‘/’, function(Request $request) use ($app) { return “bar.localhost.com”; })->host(“bar.localhost.com”); Docs: http://silex.sensiolabs.org/api/Silex/Route.html#method_host

some Twig functions / helper

Template function to generate asset URLs Usage like this: <link rel=”stylesheet” href=”{{ assets(‘styles.css’) }}”> And here is the Twig function: $app[‘twig’]->addFunction(new \Twig_SimpleFunction(‘assets’, function ($uri = ”) use ($app) { return ‘//’ . $app[‘request’]->getHttpHost() . $app[‘request’]->getBasePath() . ‘/assets/’ . trim($uri, ‘\/’); })); Template function for reading session value with dot annotation Access session Read more…

Twig asset helper

This function generates an URL for project assets. $app[‘twig’]->addFunction(new \Twig_SimpleFunction(‘asset’, function ($uri = ”) use ($app) { return ‘//’ . $app[‘request’]->getHttpHost() . $app[‘request’]->getBasePath() . ‘/PATH_TO_ASSETS/’ . trim($uri, ‘/\’); })); Usage: {{ asset(‘css/styles.css’) }} {{ asset(‘js/main.js’) }} Here are other solutions: http://silex.sensiolabs.org/doc/cookbook/assets.html