Metodas renderLayout savo MVC karkasui
Dabar sukurkime metodą renderLayout.
Šis metodas paims išdėstymo failą ir į jį įstatys
kintamųjų $title
ir $content reikšmes
(jis bus perduodamas metodo parametru ir reikš
metodo renderView veikimo rezultatą):
<?php
private function renderLayout(Page $page, $content) {
$layoutPath = $_SERVER['DOCUMENT_ROOT'] . "/project/layouts/{$page->layout}.php";
if (file_exists($layoutPath)) {
ob_start();
$title = $page->title;
include $layoutPath; // čia bus prieinami kintamieji $title ir $content
return ob_get_clean();
}
}
?>