In aAM
\n"; }; $beforeAllMiddleware = function (Request $request, Application $app) { echo "In bAM
\n"; }; // This type of global configuration does not apply to mounted controllers, // which have their own "global" configuration. $app->before($beforeAllMiddleware); $app->after($afterAllMiddleware); $app->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...', ], 2 => [ 'date' => '2015-03-29', 'author' => 'igorw', 'title' => 'Using Silex 2', 'body' => '...Especialy S1 to S2...', ], ]; // Available automatic arguments on controllers: Application, Request. $app->get('/blogs', function () use ($blogPosts) { $output = "{$post['body']}
"; })->assert('id', '\d+') ->value('id', 1) ->bind('blog_post'); $app->post('/feedback', FeedbackController::class . '::feedbackAction'); $app->get('/user/{user}', UserController::class . '::itemAction') ->convert('user', 'converter.user:convert'); /* Error handlers receive exactly these arguments, in that order. */ $app->error(function (HttpException $e, Request $request, $code) { $response = new Response('HTTP Error caught: skipping generic error handler.', // This status is ignored by Silex, which tries to ensure status code // consistency with the exception. Response::HTTP_NOT_FOUND, // But we can force it with this fake header, which is removed before // sending the response to the user agent. ['X-Status-Code' => Response::HTTP_OK]); return $response; }); $app->error(function (\Exception $e, Request $request, $code) use ($app) { if ($app['debug']) { return; } // 404.html, or 40x.html, or 4xx.html, or error.html $templates = [ 'errors/' . $code . '.html.twig', 'errors/' . substr($code, 0, 2) . 'x.html.twig', 'errors/' . substr($code, 0, 1) . 'xx.html.twig', 'errors/default.html.twig', ]; return new Response($app['twig']->resolveTemplate($templates) ->render(['code' => $code]), $code); });