require_once __DIR__.'/vendor/autoload.php'; $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__.'/views' )); $app->get('/hello/{name}', function ($name) use ($app) { return $app['twig']->render('hello.twig', array( 'name' => $name, )); }); $app->run();
require_once __DIR__.'/vendor/autoload.php'; use Silex\Application; $app = new Application(); $app->register(new \Silex\Provider\SessionServiceProvider()); $app->get('/', function () { $session = $this->get('session'); $count = $session->get('count', 0); $session->set('count', ++$count); return "You have visited this page $count times"; }); $app->run();In this example, we are registering the SessionServiceProvider, which provides a session service. Then, we define a route for the URL '/' which increments a counter stored in the session and returns the count. Finally, we run the Silex application. Package Library: Silex\Provider\SessionServiceProvider