40 lines
730 B
PHP
40 lines
730 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MyProject\Controllers;
|
|
|
|
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();
|
|
|
|
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]);
|
|
}
|
|
}
|