Introduction to Silex – Symfony2 Microframework

Silex is a PHP microframework based on Symfony2 components and Pimple (A simple PHP
Dependency Injection Container) and inspired by the Sinatra Ruby framework structure and Silex can be used to build small websites and large applications alike. It is concise, extensible, and testable.


The way to install silex via composer:

// composer.json file
"require": {
"silex/silex": "1.3.*@dev",
"twig/twig": "1.17.*@dev"
"require-dev": {
"symfony/var-dumper": "dev-master"

To load all dependency then simply run now “composer update –dev” command.

We have to require “twig” because in the application we want to use it as our template engine also “var-dumper” to add symfony2 developer dependency.

Silex-MVC Directory Structure

The below is Silex-MVC directory structure but I like about Silex is that it gives you a bonus framework that you can organize or manage in any way you want.

|-- app/
| |-- Console/ # Console application
| |-- Controllers/ # Controllers
| |-- Forms/ # Forms
| |-- Models/ # Models (AR, DBAL, ORM)
| |-- Providers/ # Providers
| |-- Resources/ # Resources (configuration, database localization)
| |-- Services/ # Services (additional classes)
| |-- Views/ # Displaying data
| `-- Bootstrap.php # Boot loader class
|-- data/ # Data (cache, logs)
|-- library/ # Libraries (AR, Pagerfanta)
|-- public/
| |-- css/ # Cascading styles
| |-- fonts/ # Fonts
| |-- img/ # Images
| |-- js/ # Java Scripts
| |-- schemes/ # Schemes
| |-- .htaccess
| |-- favicon.ico
| `-- index.php # Entrance to application
|-- vendor/ # External libraries
|-- composer.json
`-- composer.lock

In public/index.php file will create a new Silex/Application and which is our application compartment example, and this is the place we will wire the components.

// public/index.php file

require_once __DIR__ . '/../vendor/autoload.php';

$app = new Silex\Application(); // initialize silex application object

// Here you can defined your application route.

$app->get('/', function() {
    return new Response('Welcome to my new Silex app');
$app['debug'] = true; // debug mode


Silex Pros & Cons


=> Silex is open source and is licensed under the MIT license.

=> The thing that makes Silex emerge from other PHP microframeworks is the way that it’s fabricated utilizing some of the Symfony2 components. Making it very intense yet at the same time sufficiently lightweight to be viewed as a genuine micro framework.

=> Based on Pimple, Silex has a simple Dependency Injection container that comprises of only one file and one class.


=> The documentation for this system is normal, it’s useful for the most part. Yet, it is not sufficiently broad to cover everything in detail shockingly.


The Silex is smart micro PHP framework for symfony2 components also the above is the just basic idea of silex framework and if you can use silex with creating any blog type application it will helpful. The official documentation can be extremely useful and is unquestionably an absolute necessary to read on the off chance that you need to keep using Silex.

Do write us on for further queries and thoughts.

Want to work with us? We're hiring!