자체 MVC 프레임워크를 위한 renderLayout 메서드
이제 renderLayout 메서드를 만들어 봅시다.
이 메서드는 레이아웃 파일을 가져와서
변수 $title와 $content의 값을
대입할 것입니다($content는 메서드의 매개변수로 전달되며,
renderView 메서드의 실행 결과가 될 것입니다):
<?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; // 여기서 변수 $title과 $content를 사용할 수 있습니다
return ob_get_clean();
}
}
?>