ඔබේම MVC කාචය සඳහා renderLayout ක්රමය
දැන් අපි renderLayout ක්රමය සාදමු.
මෙම ක්රමය ලේඅවුට් ගොනුව ගෙන එහි $title
සහ $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();
}
}
?>