$app->get('/hello/{name}', function ($name) use ($app) { return 'Hello '.$app->escape($name); });
$app->before(function (Request $request) { // do something before each request }); $app->after(function (Request $request, Response $response) { // do something after each request });
$app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__.'/views', )); $app->get('/', function () use ($app) { return $app['twig']->render('index.html', array()); });This code registers the Twig template engine as a service provider, then uses it to render a simple HTML page. You can register other service providers for database access, caching, and more. Silex uses various packages from the Symfony ecosystem, including: - Routing (symfony/routing) - HttpFoundation (symfony/http-foundation) - EventDispatcher (symfony/event-dispatcher) - DependencyInjection (symfony/dependency-injection) - Twig (silex/twig-service-provider) - Monolog (silex/monolog-service-provider) Overall, Silex is a lightweight, flexible framework that leverages the power of Symfony components to provide a solid foundation for building PHP applications.