From 1ff80f75e0061dba369858b2df86a85bb8f8eda2 Mon Sep 17 00:00:00 2001 From: RameshT Date: Tue, 13 Aug 2024 15:10:34 +0530 Subject: [PATCH] Your commit message --- application/controllers/dummy.php | 48 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/application/controllers/dummy.php b/application/controllers/dummy.php index 2317f8b..1f64866 100644 --- a/application/controllers/dummy.php +++ b/application/controllers/dummy.php @@ -2,47 +2,53 @@ declare(strict_types=1); -// namespace MyProject\Controllers; - +namespace MyProject\Controllers; use MyProject\Models\ExampleModel; +/** + * Class ExampleController + * + * Handles the requests related to examples. + */ class ExampleController { private ExampleModel $model; - public function __construct(ExampleModel $model) - { - $this->model = $model; - } - - public function index(): void - { - $data = $this->model->getData(); - $this->render('views/example_view.php', ['data' => $data]); - } - + /** + * Display a specific item view. + * + * Retrieves an item by its ID and renders the item view. If the item is not found, + * a not found response is generated. + * + * @param integer $id The ID of the item to retrieve. + * + * @return void + */ public function show(int $id): void { $item = $this->model->find($id); if ($item === null) { $this->notFound(); + return; } $this->render('views/item_view.php', ['item' => $item]); } - private function render(string $viewPath, array $data): void + /** + * Display the index view with data. + * + * Retrieves data from the model and renders the index view. + * + * @return void + */ + public function index(): void { - extract($data); - include $viewPath; - } + $data = $this->model->getData(); - private function notFound(): void - { - http_response_code(404); - include 'views/404.php'; + $this->render('views/example_view.php', ['data' => $data]); } }