diff --git a/src/Controllers/Controller.php b/src/Controllers/Controller.php new file mode 100644 index 0000000..75bb94a --- /dev/null +++ b/src/Controllers/Controller.php @@ -0,0 +1,34 @@ +ctx->view->render($template, $data, $layout); + } + + protected function redirect(string $location): Response + { + return Response::redirect($location); + } + + protected function back(string $fallback = '/'): Response + { + $referer = $this->ctx->request->header('Referer'); + return Response::redirect($referer ?? $fallback); + } + + protected function notFound(): Response + { + return $this->ctx->view->render('errors.404', [], 'layout', 404); + } +} diff --git a/src/Controllers/HomeController.php b/src/Controllers/HomeController.php new file mode 100644 index 0000000..7797f80 --- /dev/null +++ b/src/Controllers/HomeController.php @@ -0,0 +1,16 @@ +view('home', [ + 'featured' => $this->ctx->products->featured(6), + 'categories' => $this->ctx->categories->withProductCounts(), + ]); + } +} diff --git a/src/Controllers/LocaleController.php b/src/Controllers/LocaleController.php new file mode 100644 index 0000000..d916fcf --- /dev/null +++ b/src/Controllers/LocaleController.php @@ -0,0 +1,17 @@ +ctx->session->put('locale', $locale); + } + return $this->back('/'); + } +}