46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace WizdomNetworks\WizeWeb\Core;
|
|
|
|
use WizdomNetworks\WizeWeb\Utils\Logger;
|
|
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
|
|
|
/**
|
|
* Base Controller
|
|
*
|
|
* This class provides foundational methods for all controllers, including rendering views
|
|
* and handling data passing.
|
|
*/
|
|
class Controller
|
|
{
|
|
/**
|
|
* Renders a view file and passes data to it.
|
|
*
|
|
* @param string $view The name of the view file (relative to /resources/views/).
|
|
* @param array $data Associative array of variables to pass to the view.
|
|
* @throws \Exception If the view file is not found.
|
|
*/
|
|
protected function render(string $view, array $data = []): void
|
|
{
|
|
Logger::debug("Rendering view: $view");
|
|
|
|
// Extract data to make variables available in the view
|
|
extract($data);
|
|
|
|
// Build the full path to the view file
|
|
$viewPath = __DIR__ . "/../../resources/views/$view.php";
|
|
|
|
// Debugging: Log resolved path
|
|
Logger::debug("Resolved view path: $viewPath");
|
|
|
|
// Check if the file exists before including it
|
|
if (file_exists($viewPath)) {
|
|
include $viewPath;
|
|
Logger::debug("Successfully rendered view: $view");
|
|
} else {
|
|
Logger::error("View file not found: $view | Resolved path: $viewPath");
|
|
throw new \Exception("View file not found: $view");
|
|
}
|
|
}
|
|
}
|