Last active
April 28, 2016 00:35
Star
You must be signed in to star a gist
This file contains 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 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 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