a SensioLabs Product

The PHP micro-framework
based on the Symfony Components

Warning: Silex 1.3 is not maintained anymore. Please upgrade to Silex 2.x.
You are reading the documentation for Silex 1.3. Switch to the documentation for Silex 2.0.

Table of Contents

Questions & Feedback

License

Creative Commons License Silex documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

Introduction

WARNINIG You are reading documentation for the Silex 1.x branch, which is not maintained anymore. You should upgrade to Silex 2.x.

Silex is a PHP microframework. It is built on the shoulders of Symfony and Pimple and also inspired by Sinatra.

Silex aims to be:

  • Concise: Silex exposes an intuitive and concise API.
  • Extensible: Silex has an extension system based around the Pimple service-container that makes it easy to tie in third party libraries.
  • Testable: Silex uses Symfony's HttpKernel which abstracts request and response. This makes it very easy to test apps and the framework itself. It also respects the HTTP specification and encourages its proper use.

In a nutshell, you define controllers and map them to routes, all in one step.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php

// 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, a route for /hello/{name} that matches for GET requests is defined. 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!

Website powered by Symfony and Twig, deployed on
The Silex logo is © 2010-2017 SensioLabs