keeping it small - getting to know the slim micro framework - @jeremykendall
TRANSCRIPT
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 1/135
Keeping it smallGetting to know the Slim micro framework
@JeremyKendall
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 2/135
Jeremy
Kendall
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 3/135
Jeremy
Kendall
I love to code
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 4/135
Jeremy
Kendall
I love to code
I’m terribly forgetful
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 5/135
Jeremy
Kendall
I love to code
I’m terribly forgetful
I take pictures
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 6/135
Jeremy
Kendall
I love to code
I’m terribly forgetful
I take pictures
I work at OpenSky
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 7/135
Micro framework?
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 8/135
Micro framework?
Concise codebase
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 9/135
Micro framework?
Concise codebase
Clear codebase
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 10/135
Micro framework?
Concise codebase
Clear codebase
Addresses a small set of use cases
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 11/135
Micro framework?
Concise codebase
Clear codebase
Addresses a small set of use cases
Addresses those use cases well
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 12/135
What is Slim?
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 13/135
What is Slim?
Inspired by Sinatra
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 14/135
What is Slim?
Inspired by Sinatra
Favors cleanliness over terseness
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 15/135
What is Slim?
Inspired by Sinatra
Favors cleanliness over terseness
Favors common cases over edge cases
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 16/135
Installing Slim
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 17/135
RTFM
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 18/135
RTFM ;-)
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 19/135
Don’t forget .htaccess!
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
http://docs.slimframework.com/pages/routing-url-rewriting/
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 20/135
Hello world
<?php
require '../vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 21/135
Hello world
<?php
require '../vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 22/135
Hello world
<?php
require '../vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 23/135
Hello world
<?php
require '../vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 24/135
Hello world
<?php
require '../vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 25/135
Let’s look at a
Slim application
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 26/135
Flaming Archer
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 27/135
Flaming Archer
wat
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 28/135
“Great repository names are short and memorable.
Need inspiration? How about flaming-archer.”
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 29/135
Flaming Archer
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 30/135
Flaming Archer
Photo 365 project
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 31/135
Flaming Archer
Photo 365 project
Built in 4 days (Saturday through Tuesday)
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 32/135
Flaming Archer
Photo 365 projectBuilt in 4 days (Saturday through Tuesday)
Basic application — a few bells, no whistles
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 33/135
Flaming Archer
Photo 365 projectBuilt in 4 days (Saturday through Tuesday)
Basic application — a few bells, no whistles
Routing
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 34/135
Flaming Archer
Photo 365 projectBuilt in 4 days (Saturday through Tuesday)
Basic application — a few bells, no whistles
Routing
Twig views
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 35/135
Flaming Archer
Photo 365 projectBuilt in 4 days (Saturday through Tuesday)
Basic application — a few bells, no whistles
Routing
Twig views
Middleware
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 36/135
4 views
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 37/135
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 38/135
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 39/135
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 40/135
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 41/135
phploc --exclude vendor,tests,templates .
phploc 1.6.4 by Sebastian Bergmann.
Directories: 7Files: 13
Lines of Code (LOC): 876 Cyclomatic Complexity / Lines of Code: 0.04Comment Lines of Code (CLOC): 272Non-Comment Lines of Code (NCLOC): 604
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 42/135
Configuration
return array(
'slim' => array(
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 43/135
y(
'templates.path' => __DIR__ . '/templates',
'log.level' => 4,
'log.enabled' => true,
'log.writer' => new Slim\Extras\Log\DateTimeFileWriter(
array( 'path' => __DIR__ . '/logs',
'name_format' => 'y-m-d'
)
)
),
'twig' => array(
// . . . ),
'cookies' => array(
// . . .
),
'flickr.api.key' => 'FLICKR API KEY',
'pdo' => array(
// . . . )
);
return array(
'slim' => array(
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 44/135
y(
'templates.path' => __DIR__ . '/templates',
'log.level' => 4,
'log.enabled' => true,
'log.writer' => new Slim\Extras\Log\DateTimeFileWriter(
array( 'path' => __DIR__ . '/logs',
'name_format' => 'y-m-d'
)
)
),
'twig' => array(
// . . . ),
'cookies' => array(
// . . .
),
'flickr.api.key' => 'FLICKR API KEY',
'pdo' => array(
// . . . )
);
S
return array(
'slim' => array(
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 45/135
'templates.path' => __DIR__ . '/templates',
'log.level' => 4,
'log.enabled' => true,
'log.writer' => new Slim\Extras\Log\DateTimeFileWriter(
array( 'path' => __DIR__ . '/logs',
'name_format' => 'y-m-d'
)
)
),
'twig' => array(
// . . . ),
'cookies' => array(
// . . .
),
'flickr.api.key' => 'FLICKR API KEY',
'pdo' => array(
// . . . )
);
S
Views
return array(
'slim' => array(
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 46/135
'templates.path' => __DIR__ . '/templates',
'log.level' => 4,
'log.enabled' => true,
'log.writer' => new Slim\Extras\Log\DateTimeFileWriter(
array( 'path' => __DIR__ . '/logs',
'name_format' => 'y-m-d'
)
)
),
'twig' => array(
// . . . ),
'cookies' => array(
// . . .
),
'flickr.api.key' => 'FLICKR API KEY',
'pdo' => array(
// . . . )
);
S
Views
Cookies
return array(
'slim' => array(
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 47/135
'templates.path' => __DIR__ . '/templates',
'log.level' => 4,
'log.enabled' => true,
'log.writer' => new Slim\Extras\Log\DateTimeFileWriter(
array( 'path' => __DIR__ . '/logs',
'name_format' => 'y-m-d'
)
)
),
'twig' => array(
// . . . ),
'cookies' => array(
// . . .
),
'flickr.api.key' => 'FLICKR API KEY',
'pdo' => array(
// . . . )
);
S
Views
Cookies
My stuff
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 48/135
$config = require_once __DIR__ . '/../config.php
// Prepare app
$app = new Slim\Slim($config['slim']);
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 49/135
$config = require_once __DIR__ . '/../config.php
// Prepare app
$app = new Slim\Slim($config['slim']);
Config arraygoes here
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 50/135
Routing
R i
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 51/135
Routing
$app->get('/', function () use ($app, $service) { $images = $service->findAll();
$app->render('index.html', array('images' => $images));
});
R i
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 52/135
Routing
$app->get('/', function () use ($app, $service) { $images = $service->findAll();
$app->render('index.html', array('images' => $images));
});
HTTP Method
R i
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 53/135
Routing
$app->get('/', function () use ($app, $service) { $images = $service->findAll();
$app->render('index.html', array('images' => $images));
});
HTTP MethodResource URI
R ti
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 54/135
Routing
$app->get('/', function () use ($app, $service) { $images = $service->findAll();
$app->render('index.html', array('images' => $images));
});
HTTP MethodResource URI
Anonymous Function
R ti
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 55/135
Routing
$app->get('/', function () use ($app, $service) { $images = $service->findAll();
$app->render('index.html', array('images' => $images));
});
R ti
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 56/135
Routing
$app->get('/', function () use ($app, $service) { $images = $service->findAll();
$app->render('index.html', array('images' => $images));
});
Grabs all t
R tin
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 57/135
Routing
$app->get('/', function () use ($app, $service) { $images = $service->findAll();
$app->render('index.html', array('images' => $images));
});
Grabs all t
Passes array of image data to index.html
GET
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 58/135
GET
$app->get('/:day', function($day) use ($app, $service) {
$image = $service->find($day);
if (!$image) {
$app->notFound();
}
$app->render('images.html', $image);
}
)->conditions(array('day' => '([1-9]\d?|[12]\d\d|3[0-5]\d|36[0-6])
GET
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 59/135
GET
$app->get('/:day', function($day) use ($app, $service) {
$image = $service->find($day);
if (!$image) {
$app->notFound();
}
$app->render('images.html', $image);
}
)->conditions(array('day' => '([1-9]\d?|[12]\d\d|3[0-5]\d|36[0-6])
URL parameter
GET
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 60/135
GET
$app->get('/:day', function($day) use ($app, $service) {
$image = $service->find($day);
if (!$image) {
$app->notFound();
}
$app->render('images.html', $image);
}
)->conditions(array('day' => '([1-9]\d?|[12]\d\d|3[0-5]\d|36[0-6])
URL parameter... gets passed as an
argument
GET
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 61/135
GET
$app->get('/:day', function($day) use ($app, $service) {
$image = $service->find($day);
if (!$image) {
$app->notFound();
}
$app->render('images.html', $image);
}
)->conditions(array('day' => '([1-9]\d?|[12]\d\d|3[0-5]\d|36[0-6])
URL parameter... gets passed as an
argument
Condition
GET
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 62/135
GET
$app->get('/:day', function($day) use ($app, $service) {
$image = $service->find($day);
if (!$image) {
$app->notFound();
}
$app->render('images.html', $image);
}
)->conditions(array('day' => '([1-9]\d?|[12]\d\d|3[0-5]\d|36[0-6])
URL parameter... gets passed as an
argument
Condition 1 to 366
GET
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 63/135
GET
$app->get('/:day', function($day) use ($app, $service) {
$image = $service->find($day);
if (!$image) {
$app->notFound();
}
$app->render('images.html', $image);
}
)->conditions(array('day' => '([1-9]\d?|[12]\d\d|3[0-5]\d|36[0-6])
404!
POST (with redirect)
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 64/135
POST (with redirect)
$app->post('/admin/add-photo', function() use ($app, $service)
$data = $app->request()->post(); $service->save($data);
$app->redirect('/admin');
}
);
POST (with redirect)
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 65/135
POST (with redirect)
$app->post('/admin/add-photo', function() use ($app, $service)
$data = $app->request()->post(); $service->save($data);
$app->redirect('/admin');
}
);
$_POST data is i
the request objec
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 66/135
Multiple methods
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 67/135
Multiple methods
$app->map('/login', function() { // Login
})->via('GET', 'POST');
Multiple methods
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 68/135
Multiple methods
$app->map('/login', function() { // Login
})->via('GET', 'POST');
Not an HTTP Method
Multiple methods
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 69/135
Multiple methods
$app->map('/login', function() { // Login
})->via('GET', 'POST');
Not an HTTP Method
via() is the
awesome sauce
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 70/135
Logging and flash messaging
$app->post('/admin/clear-cache', function() use ($app) {
$log $app getLog();
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 71/135
$log = $app->getLog();
$cleared = null;
$clear = $app->request()->post('clear');
if ($clear == 1) {
if (apc_clear_cache('user')) {
$cleared = 'Cache was successfully cleared!';
} else {
$cleared = 'Cache was not cleared!';
$log->error('Cache not cleared'); }
}
$app->flash('cleared', $cleared);
$app->redirect('/admin');
}
);
$app->post('/admin/clear-cache', function() use ($app) {
$log $app >getLog(); Get the log from $app
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 72/135
$log = $app->getLog();
$cleared = null;
$clear = $app->request()->post('clear');
if ($clear == 1) {
if (apc_clear_cache('user')) {
$cleared = 'Cache was successfully cleared!';
} else {
$cleared = 'Cache was not cleared!';
$log->error('Cache not cleared'); }
}
$app->flash('cleared', $cleared);
$app->redirect('/admin');
}
);
Get the log from $app
$app->post('/admin/clear-cache', function() use ($app) {
$log $app >getLog(); Get the log from $app
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 73/135
$log = $app->getLog();
$cleared = null;
$clear = $app->request()->post('clear');
if ($clear == 1) {
if (apc_clear_cache('user')) {
$cleared = 'Cache was successfully cleared!';
} else {
$cleared = 'Cache was not cleared!';
$log->error('Cache not cleared'); }
}
$app->flash('cleared', $cleared);
$app->redirect('/admin');
}
);
Get the log from $app
Erro
$app->post('/admin/clear-cache', function() use ($app) {
$log = $app->getLog(); Get the log from $app
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 74/135
$log = $app->getLog();
$cleared = null;
$clear = $app->request()->post('clear');
if ($clear == 1) {
if (apc_clear_cache('user')) {
$cleared = 'Cache was successfully cleared!';
} else {
$cleared = 'Cache was not cleared!';
$log->error('Cache not cleared'); }
}
$app->flash('cleared', $cleared);
$app->redirect('/admin');
}
);
Get the log from $app
Erro
Flash message availthe next reque
Middleware
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 75/135
Middleware
“. . . a Slim application can have middlewarethat may inspect, analyze, or modify the application environment, request, and
response before and/or after the Slimapplication is invoked.”
http://docs.slimframework.com/pages/middleware-overview/
Hooks
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 76/135
Hooks
Hooks
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 77/135
slim.before
Hooks
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 78/135
slim.before
slim.before.router
Hooks
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 79/135
slim.before
slim.before.router
slim.before.dispatch
Hooks
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 80/135
slim.before
slim.before.router
slim.before.dispatch
slim.after.dispatch
Hooks
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 81/135
slim.before
slim.before.router
slim.before.dispatch
slim.after.dispatch
slim.after.router
Hooks
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 82/135
slim.before
slim.before.router
slim.before.dispatch
slim.after.dispatch
slim.after.router
slim.after
Hooks
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 83/135
slim.before
slim.before.router
slim.before.dispatch
slim.after.dispatch
slim.after.router
slim.after
class MyMiddleware extends \Slim\Middleware
{
public function call()
{
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 84/135
{
//The Slim application
$app = $this->app;
//The Environment object
$env = $app->environment();
//The Request object
$req = $app->request();
//The Response object
$res = $app->response();
//Optionally call the next middleware
$this->next->call();
}}
class MyMiddleware extends \Slim\Middleware
{
public function call()
{
Extend th
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 85/135
{
//The Slim application
$app = $this->app;
//The Environment object
$env = $app->environment();
//The Request object
$req = $app->request();
//The Response object
$res = $app->response();
//Optionally call the next middleware
$this->next->call();
}
}
class MyMiddleware extends \Slim\Middleware
{
public function call()
{
Extend th
Define call()
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 86/135
{
//The Slim application
$app = $this->app;
//The Environment object
$env = $app->environment();
//The Request object
$req = $app->request();
//The Response object
$res = $app->response();
//Optionally call the next middleware
$this->next->call();
}
}
Define call()
class MyMiddleware extends \Slim\Middleware{
public function call()
{
Extend th
Define call()
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 87/135
{
//The Slim application
$app = $this->app;
//The Environment object
$env = $app->environment();
//The Request object
$req = $app->request();
//The Response object
$res = $app->response();
//Optionally call the next middleware
$this->next->call();
}
}
Define call()
Inspect, analyze,and modify!
class MyMiddleware extends \Slim\Middleware{
public function call()
{
Extend th
Define call()
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 88/135
{
//The Slim application
$app = $this->app;
//The Environment object
$env = $app->environment();
//The Request object
$req = $app->request();
//The Response object
$res = $app->response();
//Optionally call the next middleware
$this->next->call();
}
}
Define call()
On to the nex
Inspect, analyze,and modify!
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 89/135
Middleware + Hooks = WIN
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 90/135
Navigation example
namespace Tsf\Middleware;
use \Zend\Authentication\AuthenticationService;
class Navigation extends \Slim\Middleware
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 91/135
g
{
/** * @var \Zend\Authentication\AuthenticationService
*/
private $auth;
public function __construct(AuthenticationService $auth)
{
$this->auth = $auth; }
public function call()
{
// . . .
}
}
namespace Tsf\Middleware;
use \Zend\Authentication\AuthenticationService;
class Navigation extends \Slim\Middleware extends
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 92/135
g
{
/** * @var \Zend\Authentication\AuthenticationService
*/
private $auth;
public function __construct(AuthenticationService $auth)
{
$this->auth = $auth; }
public function call()
{
// . . .
}
}
extends
namespace Tsf\Middleware;
use \Zend\Authentication\AuthenticationService;
class Navigation extends \Slim\Middleware extends
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 93/135
g
{
/** * @var \Zend\Authentication\AuthenticationService
*/
private $auth;
public function __construct(AuthenticationService $auth)
{
$this->auth = $auth; }
public function call()
{
// . . .
}
}
Constructor injectionFTW
extends
public function call()
{
$app = $this->app;
$auth = $this->auth;
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 94/135
$auth = $this >auth;
$req = $app->request();
$home = array('caption' => 'Home', 'href' => '/');
$admin = array('caption' => 'Admin', 'href' => '/admin');
$login = array('caption' => 'Login', 'href' => '/login');
$logout = array('caption' => 'Logout', 'href' => '/logout');
if ($auth->hasIdentity()) {
$navigation = array($home, $admin, $logout); } else {
$navigation = array($home, $login);
}
// . . .
}
public function call()
{
$app = $this->app;
$auth = $this->auth;Arrays ofnav items
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 95/135
$auth $this >auth;
$req = $app->request();
$home = array('caption' => 'Home', 'href' => '/');
$admin = array('caption' => 'Admin', 'href' => '/admin');
$login = array('caption' => 'Login', 'href' => '/login');
$logout = array('caption' => 'Logout', 'href' => '/logout');
if ($auth->hasIdentity()) {
$navigation = array($home, $admin, $logout); } else {
$navigation = array($home, $login);
}
// . . .
}
nav items
public function call()
{
$app = $this->app;
$auth = $this->auth;Arrays ofnav items
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 96/135
$auth $this >auth;
$req = $app->request();
$home = array('caption' => 'Home', 'href' => '/'); $admin = array('caption' => 'Admin', 'href' => '/admin');
$login = array('caption' => 'Login', 'href' => '/login');
$logout = array('caption' => 'Logout', 'href' => '/logout');
if ($auth->hasIdentity()) {
$navigation = array($home, $admin, $logout); } else {
$navigation = array($home, $login);
}
// . . .
}
nav items
Nav differs on auth st
public function call()
{
// . . .
$this->app->hook('slim.before.router', function () use (...) {
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 97/135
$ pp ( , () ( ) {
foreach ($navigation as &$link) {
if ($link['href'] == $req->getPath()) { $link['class'] = 'active';
} else {
$link['class'] = '';
}
}
$app->view()
->appendData(array('navigation' => $navigation));
}
);
$this->next->call();}
public function call()
{
// . . .
$this->app->hook('slim.before.router', function () use (...) {
Delicious hookgoodness
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 98/135
pp ( , () ( ) {
foreach ($navigation as &$link) {
if ($link['href'] == $req->getPath()) { $link['class'] = 'active';
} else {
$link['class'] = '';
}
}
$app->view()
->appendData(array('navigation' => $navigation));
}
);
$this->next->call();}
public function call()
{
// . . .
$this->app->hook('slim.before.router', function () use (...) {
Delicious hookgoodness
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 99/135
pp ,
foreach ($navigation as &$link) {
if ($link['href'] == $req->getPath()) { $link['class'] = 'active';
} else {
$link['class'] = '';
}
}
$app->view()
->appendData(array('navigation' => $navigation));
}
);
$this->next->call();}
Matchdispatched p
public function call()
{
// . . .
$this->app->hook('slim.before.router', function () use (...) {
Delicious hookgoodness
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 100/135
foreach ($navigation as &$link) {
if ($link['href'] == $req->getPath()) { $link['class'] = 'active';
} else {
$link['class'] = '';
}
}
$app->view()
->appendData(array('navigation' => $navigation));
}
);
$this->next->call();}
Matchdispatched p
Appen$navigatio
view
public function call()
{
// . . .
$this->app->hook('slim.before.router', function () use (...) {
Delicious hookgoodness
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 101/135
foreach ($navigation as &$link) {
if ($link['href'] == $req->getPath()) { $link['class'] = 'active';
} else {
$link['class'] = '';
}
}
$app->view()
->appendData(array('navigation' => $navigation));
}
);
$this->next->call();}
Matchdispatched p
Appen$navigatio
viewOn to the next!
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 102/135
Views
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 103/135
Two great tastesthat taste great together
Twig
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 104/135
Twig
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 105/135
Concise
Twig
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 106/135
Concise
Template oriented
Twig
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 107/135
Concise
Template oriented
Fast
Twig
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 108/135
Concise
Template oriented
Fast
Multiple inheritance
Twig
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 109/135
Concise
Template oriented
Fast
Multiple inheritance
Blocks
Twig
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 110/135
Concise
Template oriented
Fast
Multiple inheritance
Blocks
Automatic escaping
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 111/135
layout.htand
index.htm
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 112/135
layout.html
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 113/135
<title>{% block page_title %} {% endblock %}</tit
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 114/135
<ul class="nav">
{% for link in navigation %}
<li class="{{link.class}}">
<a href="{{link.href}}">{{link.caption}}<
</li>
{% endfor %}
</ul>
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 115/135
<h1>365 Days of Photography</h1>
<h3>Photographer: Jeremy Kendall</h3>
{% block content %} {% endblock %}
<hr />
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 116/135
index.html
{% extends 'layout.html' %}
{% block page_title %}365.jeremykendall.net{% endblock %}
{% block content %}
{% for image in images %}
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 117/135
g g
<div class="row">
<div class="span6"> <h2><a href="/{{image.day}}">{{image.day}}/365</a></h2 <p>
<a href="/{{image.day}}">
<img src="{{image.sizes.size.5.source}}" />
</a>
</p> <p>Posted {{image.posted|date("m/d/Y")}}</p>
</div></div>
{% else %}
<p>No images in project</p>
{% endfor %}{% endblock %}
{% extends 'layout.html' %}
{% block page_title %}365.jeremykendall.net{% endblock %}
{% block content %}
{% for image in images %}
extends
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 118/135
<div class="row">
<div class="span6"> <h2><a href="/{{image.day}}">{{image.day}}/365</a></h2 <p>
<a href="/{{image.day}}">
<img src="{{image.sizes.size.5.source}}" />
</a>
</p> <p>Posted {{image.posted|date("m/d/Y")}}</p>
</div></div>
{% else %}
<p>No images in project</p>
{% endfor %}{% endblock %}
{% extends 'layout.html' %}
{% block page_title %}365.jeremykendall.net{% endblock %}
{% block content %}
{% for image in images %}
extends
<title
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 119/135
<div class="row">
<div class="span6"> <h2><a href="/{{image.day}}">{{image.day}}/365</a></h2 <p>
<a href="/{{image.day}}">
<img src="{{image.sizes.size.5.source}}" />
</a>
</p> <p>Posted {{image.posted|date("m/d/Y")}}</p>
</div></div>
{% else %}
<p>No images in project</p>
{% endfor %}{% endblock %}
{% extends 'layout.html' %}
{% block page_title %}365.jeremykendall.net{% endblock %}
{% block content %}
{% for image in images %}
extends
<title
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 120/135
<div class="row">
<div class="span6"> <h2><a href="/{{image.day}}">{{image.day}}/365</a></h2 <p>
<a href="/{{image.day}}">
<img src="{{image.sizes.size.5.source}}" />
</a>
</p> <p>Posted {{image.posted|date("m/d/Y")}}</p>
</div></div>
{% else %}
<p>No images in project</p>
{% endfor %}{% endblock %}
{% extends 'layout.html' %}
{% block page_title %}365.jeremykendall.net{% endblock %}
{% block content %}
{% for image in images %}
extends
<title
iterator
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 121/135
<div class="row">
<div class="span6"> <h2><a href="/{{image.day}}">{{image.day}}/365</a></h2 <p>
<a href="/{{image.day}}">
<img src="{{image.sizes.size.5.source}}" />
</a>
</p> <p>Posted {{image.posted|date("m/d/Y")}}</p>
</div></div>
{% else %}
<p>No images in project</p>
{% endfor %}{% endblock %}
{% extends 'layout.html' %}
{% block page_title %}365.jeremykendall.net{% endblock %}
{% block content %}
{% for image in images %}
di l " "
extends
<title
iterator
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 122/135
<div class="row">
<div class="span6"> <h2><a href="/{{image.day}}">{{image.day}}/365</a></h2 <p>
<a href="/{{image.day}}">
<img src="{{image.sizes.size.5.source}}" />
</a>
</p> <p>Posted {{image.posted|date("m/d/Y")}}</p>
</div></div>
{% else %}
<p>No images in project</p>
{% endfor %}{% endblock %}
else
{% extends 'layout.html' %}
{% block page_title %}365.jeremykendall.net{% endblock %}
{% block content %}
{% for image in images %}
di l " "
extends
<title
iterator
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 123/135
<div class="row">
<div class="span6"> <h2><a href="/{{image.day}}">{{image.day}}/365</a></h2 <p>
<a href="/{{image.day}}">
<img src="{{image.sizes.size.5.source}}" />
</a>
</p> <p>Posted {{image.posted|date("m/d/Y")}}</p>
</div></div>
{% else %}
<p>No images in project</p>
{% endfor %}{% endblock %}
else
format
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 124/135
login.htm
{% extends 'layout.html' %}
{% block page_title %}365.jeremykendall.net | Login{% endblock %}
{% block content %}
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 125/135
{ }
<div class="row">
<div class="span4">
<h2>Login</h2>
{% if flash.error %}
<p style="color: red;">{{flash.error}}</p>
{% endif %} <form name="login" id="login" class="well" method="post">
// Login form . . . </form>
</div>
</div>
{% endblock %}
{% extends 'layout.html' %}
{% block page_title %}365.jeremykendall.net | Login{% endblock %}
{% block content %}
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 126/135
<div class="row">
<div class="span4">
<h2>Login</h2>
{% if flash.error %}
<p style="color: red;">{{flash.error}}</p>
{% endif %} <form name="login" id="login" class="well" method="post">
// Login form . . . </form>
</div>
</div>
{% endblock %}
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 127/135
The other viewswould be redundant
GOTO 0
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 128/135
Small but powerfulGOTO 0
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 129/135
p
Small but powerfulGOTO 0
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 130/135
p
Excellent tools to write elegant code
Small but powerfulGOTO 0
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 131/135
Excellent tools to write elegant code
Routing, middleware & hooks, views
Small but powerfulGOTO 0
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 132/135
Excellent tools to write elegant code
Routing, middleware & hooks, views
I just scratched the surface
Read
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 133/135
Slim: slimframework.com
Twig: twig.sensiolabs.org
Composer: getcomposer.org
MicroPHP Manifesto: microphp.org
Flaming Archer: http://git.io/rH0nrg
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 134/135
Questions?
Thanks!
8/13/2019 Keeping It Small - Getting to know the Slim micro framework - @JeremyKendall
http://slidepdf.com/reader/full/keeping-it-small-getting-to-know-the-slim-micro-framework-jeremykendall 135/135
@jeremykendall