use Silex\Application; $app = new Application(); $app->get('/', function() { return 'Hello, world!'; }); $app->run();
use Silex\Application; $app = new Application(); $app->post('/login', function(Application $app, Request $request) { $username = $request->get('username'); $password = $request->get('password'); // do something with username and password return 'Welcome, ' . $username . '!'; }); $app->run();
use Silex\Application; use Silex\Provider\TwigServiceProvider; $app = new Application(); $app->register(new TwigServiceProvider(), [ 'twig.path' => __DIR__.'/views', ]); $app->get('/hello/{name}', function($name) use ($app) { return $app['twig']->render('hello.html', [ 'name' => $name, ]); }); $app->run();This example uses the Twig templating engine to render a simple "hello" view with the name of the user in the URL. The `TwigServiceProvider` is registered as a package library and configured with the path to the view templates. The route handler uses the `$app` object to retrieve the Twig environment and render the template with the supplied name parameter.