Silex is a PHP microframework for PHP 5.3. It is built on the shoulders of Symfony2 and Pimple and also inspired by sinatra.
A microframework provides the guts for building simple single-file apps. Silex aims to be:
In a nutshell, you define controllers and map them to routes, all in one step.
Let’s go!:
// web/index.php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/hello/{name}', function ($name) use ($app) {
return 'Hello '.$app->escape($name);
});
$app->run();
All that is needed to get access to the Framework is to include the autoloader.
Next we define a route to /hello/{name} that matches for GET requests. When the route matches, the function is executed and the return value is sent back to the client.
Finally, the app is run. Visit /hello/world to see the result. It’s really that easy!
Installing Silex is as easy as it can get. Download the archive file, extract it, and you’re done!