32. Flaming Archer
Photo 365 project
Built in 4 days (Saturday through Tuesday)
Basic application — a few bells, no whistles
33. Flaming Archer
Photo 365 project
Built in 4 days (Saturday through Tuesday)
Basic application — a few bells, no whistles
Routing
34. Flaming Archer
Photo 365 project
Built in 4 days (Saturday through Tuesday)
Basic application — a few bells, no whistles
Routing
Twig views
35. Flaming Archer
Photo 365 project
Built in 4 days (Saturday through Tuesday)
Basic application — a few bells, no whistles
Routing
Twig views
Middleware
51. Routing
$app->get('/', function () use ($app, $service) {
$images = $service->findAll();
$app->render('index.html', array('images' => $images));
}
);
52. Routing
HTTP Method
$app->get('/', function () use ($app, $service) {
$images = $service->findAll();
$app->render('index.html', array('images' => $images));
}
);
53. Routing
Resource URI
HTTP Method
$app->get('/', function () use ($app, $service) {
$images = $service->findAll();
$app->render('index.html', array('images' => $images));
}
);
54. Routing
Resource URI
HTTP Method Anonymous Function
$app->get('/', function () use ($app, $service) {
$images = $service->findAll();
$app->render('index.html', array('images' => $images));
}
);
55. Routing
$app->get('/', function () use ($app, $service) {
$images = $service->findAll();
$app->render('index.html', array('images' => $images));
}
);
56. Routing
$app->get('/', function () use ($app, $service) { Grabs all the pics
$images = $service->findAll();
$app->render('index.html', array('images' => $images));
}
);
57. Routing
$app->get('/', function () use ($app, $service) { Grabs all the pics
$images = $service->findAll();
$app->render('index.html', array('images' => $images));
}
);
Passes array of image data to index.html
58. 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]dd|3[0-5]d|36[0-6])'));
59. GET
URL parameter
$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]dd|3[0-5]d|36[0-6])'));
60. GET ... gets passed as an
URL parameter argument
$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]dd|3[0-5]d|36[0-6])'));
61. GET ... gets passed as an
URL parameter argument
$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]dd|3[0-5]d|36[0-6])'));
Condition
62. GET ... gets passed as an
URL parameter argument
$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]dd|3[0-5]d|36[0-6])'));
Condition 1 to 366
63. GET
$app->get('/:day', function($day) use ($app, $service) {
$image = $service->find($day);
if (!$image) {
$app->notFound(); 404!
}
$app->render('images.html', $image);
}
)->conditions(array('day' => '([1-9]d?|[12]dd|3[0-5]d|36[0-6])'));
65. 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 in
); the request object
66. 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 in
); the request object
302 Redirect
71. $app->post('/admin/clear-cache', function() use ($app) {
$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');
}
);
72. $app->post('/admin/clear-cache', function() use ($app) {
$log = $app->getLog(); Get the log from $app
$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');
}
);
73. $app->post('/admin/clear-cache', function() use ($app) {
$log = $app->getLog(); Get the log from $app
$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'); Error!
}
}
$app->flash('cleared', $cleared);
$app->redirect('/admin');
}
);
74. $app->post('/admin/clear-cache', function() use ($app) {
$log = $app->getLog(); Get the log from $app
$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'); Error!
}
}
$app->flash('cleared', $cleared); Flash message available in
$app->redirect('/admin'); the next request.
}
);
75. Middleware
“The purpose of middleware is to inspect,
analyze, or modify the application
environment, request, and response before
and/or after the Slim application is
invoked.”
http://docs.slimframework.com/pages/middleware-overview/