55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MyProject\Controllers;
|
|
|
|
use MyProject\Models\ExampleModel;
|
|
|
|
/**
|
|
* Class ExampleController
|
|
*
|
|
* Handles the requests related to examples.
|
|
*/
|
|
class ExampleController
|
|
{
|
|
private ExampleModel $model;
|
|
|
|
/**
|
|
* 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]);
|
|
}
|
|
|
|
/**
|
|
* Display the index view with data.
|
|
*
|
|
* Retrieves data from the model and renders the index view.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function index(): void
|
|
{
|
|
$data = $this->model->getData();
|
|
|
|
$this->render('views/example_view.php', ['data' => $data]);
|
|
}
|
|
}
|