public function index() { $data = ['apartamentTypes' => $this->query->getApartamentTypes(), 'cityList' => $this->query->getCityList(), 'sizeList' => $this->query->getSizeList(), 'view' => 'index']; if (isset($_SESSION['lastBookingId'])) { $data['successBooking'] = $this->query->getBooking($_SESSION['lastBookingId']); unset($_SESSION['lastBookingId']); } return Views::view($data); }
<?php namespace Nord; use Exception; class Views { protected static $viewsDir; protected static $layout; static function init() { self::$viewsDir = __DIR__ . '/Views/'; self::$layout = __DIR__ . '/Views/layout.view.php'; } public static function view($data) { $view = $data['view']; if (!file_exists(self::$viewsDir . $view . '.view.php')) { throw new Exception('View "' . $view . '" not found'); } self::renderLayout($data); } protected static function renderLayout($data) { include self::$layout; } } Views::init();