Silex


a low fat alternative

Like all good presentations...

There are gifs.

The inevitable self promotion...

So, Silex?

A micro what?

Everything you need for building this:

Also, this:

So, PHP 5.3?

So, Symfony components?

So, Pimple?

Good, huh?

So why is it good?

First up, a standard example...

Silex, Hello World

Silex is installable via composer.

// composer.json { "require": { "silex/silex": "~1.1" } }

Silex, Hello World

After installation, the simplest example is:

// 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();

So what?

Where does the power come from?

An example

require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app->register(new Silex\Provider\DoctrineServiceProvider(), array( 'db.options' => array( 'driver' => 'pdo_sqlite', 'path' => __DIR__.'/app.db', ), ));

An example, cont'd

$app->get('/blog/{id}', function ($id) use ($app) { $sql = "SELECT * FROM posts WHERE id = ?"; $post = $app['db']->fetchAssoc($sql, array((int) $id)); return "

{$post['title']}

". "

{$post['body']}

"; });

Twig

$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, )); });

So I could go on...

But, I won't

No really, I won't

So if you wanna check out silex:

http://silex.sensiolabs.org


A great place to get started:

composer create-project fabpot/silex-skeleton silex


https://github.com/silexphp/Silex-Skeleton

Questions?