function router() { $config = getConfig(); $uri = $_SERVER['REQUEST_URI']; $type = $_SERVER['REQUEST_METHOD']; $routers = $config['route']; $action = null; foreach ($routers as $key => $value) { if (preg_match($key, $uri)) { if ($type === $value['type']) { $action = $value['action']; $action(); break; } } } if (empty($action)) { $twig = getTwig(); echo $twig->render('/View/404.html.twig', ['uri' => $uri]); } }
function editAction() { $twig = getTwig(); $item = getItemsByIds([$_GET['id']])[0]; echo $twig->render('/View/edit.html.twig', ['action' => '/update', 'item' => $item]); }
function homeAction() { $twig = getTwig(); echo $twig->render('/View/home.html.twig', []); }
function newAction() { $twig = getTwig(); echo $twig->render('/View/new.html.twig', ['action' => '/create']); }