<?php require_once __dir__.'/vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; /** * Simple skeleton for Silex * * Run in PHP >=5.4: $ php -S localhost:8080 -t web web/index.php * Assuming that your webroot are in web and your app file is index.php. */ $app = new Silex\Application(); $app['debug'] = true; /** * Simple controller */ $app->get('/hello/{name}', function (Request $request, $name) { return "hello {$name}. Welcome to my firts app in Silex"; }) ->assert('name', '[a-zA-z0-9]') // Your param constraint ->convert('name', function($v){ return strtoupper($v); }) // Transform your param before ->value('name', ''); // Default value /** * Redirect controller */ $app->get('/', function(Silex\Application $app){ return $app->redirect('/hello'); }); /** * Manage errors: */ $app->error(function(\Exception $e, $code) use($app) { if($app['debug']) { return; } return new Response('Something is wrong'); }); $app->run();