2024-08-12 08:52:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-08-13 09:40:34 +00:00
|
|
|
namespace MyProject\Controllers;
|
2024-08-12 08:52:09 +00:00
|
|
|
|
|
|
|
use MyProject\Models\ExampleModel;
|
|
|
|
|
|
|
|
class ExampleController
|
|
|
|
{
|
|
|
|
private ExampleModel $model;
|
|
|
|
|
|
|
|
public function show(int $id): void
|
|
|
|
{
|
|
|
|
$item = $this->model->find($id);
|
|
|
|
|
|
|
|
if ($item === null) {
|
|
|
|
$this->notFound();
|
2024-08-13 09:40:34 +00:00
|
|
|
|
2024-08-12 08:52:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->render('views/item_view.php', ['item' => $item]);
|
|
|
|
}
|
|
|
|
|
2024-08-13 09:40:34 +00:00
|
|
|
/**
|
|
|
|
* Display the index view with data.
|
|
|
|
*
|
|
|
|
* Retrieves data from the model and renders the index view.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function index(): void
|
2024-08-12 08:52:09 +00:00
|
|
|
{
|
2024-08-13 09:40:34 +00:00
|
|
|
$data = $this->model->getData();
|
2024-08-12 08:52:09 +00:00
|
|
|
|
2024-08-13 09:40:34 +00:00
|
|
|
$this->render('views/example_view.php', ['data' => $data]);
|
2024-08-12 08:52:09 +00:00
|
|
|
}
|
|
|
|
}
|