use Symfony\Component\HttpFoundation\Response; $app->before(function () use($app, $snippets_model) { $categories = $snippets_model->get_categories(); $app["twig"]->addGlobal("categories", $categories); }); $app->get('/', function ($page) use($app, $snippets_model) { $snippets = $snippets_model->get_all(); $pages = $snippets_model->get_pages_all(); $app["twig"]->addGlobal("actualPage", array("page" => "home", "category" => "all")); return $app['twig']->render('snippets.twig', array('snippets' => $snippets, "pages" => $pages)); })->value('page', 1)->bind('home'); $app->get('/category/{category}/{page}', function ($category = "all", $page = 1) use($app, $snippets_model) { if ($category == "all") { $snippets = $snippets_model->get_all($page); $pages = $snippets_model->get_pages_all($page); $cat_details = array('slug' => 'all', 'title' => 'All', 'count' => $snippets_model->get_snippets_count()); } else { $cat_details = $snippets_model->get_cat_details($category); $cat_details = $cat_details[0]; $snippets = $snippets_model->get_by_category($category, $page); $pages = $snippets_model->get_pages_by_category($cat_details['id'], $page); } $app["twig"]->addGlobal("actualPage", array("page" => "category", "category" => $category)); return $app['twig']->render('snippets.twig', array('snippets' => $snippets, "pages" => $pages, 'catdetails' => $cat_details)); })->value('page', 1)->bind('category'); $app->post('/add_snippet', function (Request $request) use($app, $snippets_model) { $title = $request->get('title'); $message = $request->get('message'); $category = $request->get('category'); if (empty($title) || empty($message) || empty($category)) { die('error');