<?php

namespace App\Core;

class Controller {
    protected function view($name, $data = []) {
        extract($data);
        $viewFile = __DIR__ . "/../../views/{$name}.php";
        if (file_exists($viewFile)) {
            require $viewFile;
        } else {
            echo "View {$name} not found";
        }
    }

    protected function json($data) {
        header('Content-Type: application/json');
        echo json_encode($data);
    }

    protected function redirect($url) {
        header("Location: {$url}");
        exit;
    }
}