get('/', function () use ($app) {
return $app['twig']->render('index.html.twig', []);
})
->bind('homepage');
$blogPosts = [
1 => [
'date' => '2011-03-29',
'author' => 'igorw',
'title' => 'Using Silex',
'body' => '...It takes time on version changes...',
],
];
// Available automatic arguments on controllers: Application, Request.
$app->get('/blog', function () use ($blogPosts) {
$output = '';
foreach ($blogPosts as $post) {
$output .= $post ['title'];
$output .= '
';
}
return $output;
});
$app->get('/blog/{id}', function (Application $app, $id) use ($blogPosts) {
if (!isset ($blogPosts [$id])) {
$app->abort(Response::HTTP_NOT_FOUND, "Post $id does not exist.");
}
$post = $blogPosts [$id];
return "
{$post['body']}
"; }); $app->post('/feedback', function (Application $app, Request $request) { $message = $request->get('message'); mail($app['app.mail_to'], '[YourSite] Feedback', $message); return new Response ('Thank you for your feedback!', Response::HTTP_CREATED); }); $app->get('/user/{user}', function (User $user) { return "