function sites($app) { $app->get('/sites', function ($request, $response, $args) { $sites = new Sites_Controller(); $skills = new Skills_Controller(); $images = new Images_Controller(); $return = ['auth' => $this->auth, 'user' => $this->user, 'sites' => $sites->getAll(), 'skills' => $skills->getAll(), 'images' => $images->getAll()]; return $this->view->render($response, 'sites.html', $return); }); $app->post('/sites/add', function ($request, $response, $args) { $sites = new Sites_Controller(); $sites->add($request, $response, $args); // maybe I need to use flash messages //http://help.slimframework.com/discussions/problems/12059-how-to-display-flash-message-in-twig-view // https://github.com/slimphp/Slim-Flash // only works in v2 //$app->redirect('/skills'); return $response->withStatus(302)->withHeader('Location', '/sites'); }); $app->get('/sites/edit', function ($request, $response, $args) { $sites = new Sites_Controller(); $site = $sites->getSite($request, $response, $args); $skills = new Skills_Controller(); $skills = $skills->getAll(); $images = new Images_Controller(); $images = $images->getAll(); foreach ($skills as &$skill) { foreach ($site['skills'] as $siteSkill) { if ($siteSkill['id'] == $skill['id']) { $skill['inUse'] = true; } } } foreach ($images as &$image) { foreach ($site['images'] as $siteImage) { if ($siteImage['id'] == $image['id']) { $image['inUse'] = true; } } } $return = ['auth' => $this->auth, 'user' => $this->user, 'site' => $site, 'skills' => $skills, 'images' => $images]; return $this->view->render($response, '/forms/editSites.html', $return); }); $app->post('/sites/edit', function ($request, $response, $args) { $sites = new Sites_Controller(); $site = $sites->edit($request, $response, $args); return $response->withStatus(302)->withHeader('Location', '/sites'); }); $app->post('/sites/delete', function ($request, $response, $args) { $sites = new Sites_Controller(); $sites->delete($request, $response, $args); return $response->withStatus(302)->withHeader('Location', '/sites'); }); return $app; }