Last active
April 28, 2016 00:35
-
-
Save The-Quill/6ca2d7c767ee26cba6d4dcbdd0502f03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function create($values){ | |
?> | |
<h3> | |
<?= $values['name'] ?> | |
</h3> | |
<p> | |
<?= $values['desc'] ?> | |
</p> | |
<?php | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('ViewManager.php'); | |
$view = new ViewManager(); | |
$view->injectContent('home', | |
array( | |
'name' => 'A website!', | |
'desc' => "Lorem ipsum dolor...." | |
) | |
); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ViewManager { | |
function __construct(){ | |
include 'views/header.html'; | |
include 'views/navbar.html'; | |
} | |
private function resolveViewName($viewName){ | |
return $viewName; // will fix viewNames and check for bad attempts | |
} | |
private function finishContent(){ | |
include 'views/end.html'; | |
} | |
public function injectContent($viewName, $values){ | |
$viewNameResolved = self::resolveViewName($viewName); | |
$view = include('views/' . $viewNameResolved . '.php'); // puts create into the global scope | |
create($values); | |
self::finishContent(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment