2024-12-25 23:02:09 +01:00
|
|
|
<?php
|
|
|
|
class View
|
|
|
|
{
|
2024-12-26 02:00:33 +01:00
|
|
|
private $data = [];
|
|
|
|
|
|
|
|
public function render($view, $data = [], $layout = 'base') {
|
|
|
|
// Store the data
|
|
|
|
$this->data = $data;
|
2024-12-25 23:02:09 +01:00
|
|
|
|
|
|
|
// Capture the view content
|
|
|
|
ob_start();
|
|
|
|
require_once views . $view . '.php';
|
|
|
|
$content = ob_get_clean();
|
|
|
|
|
|
|
|
// Include the base layout and inject the view content
|
2024-12-26 02:00:33 +01:00
|
|
|
require_once views . "layouts/$layout.php";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Safely get a value from the data array
|
|
|
|
*/
|
|
|
|
public function get($key) {
|
|
|
|
return $this->data[$key] ?? null;
|
2024-12-25 23:02:09 +01:00
|
|
|
}
|
|
|
|
}
|