Skip to content

Instantly share code, notes, and snippets.

@The-Quill The-Quill/ViewManager.php
Last active Apr 28, 2016

Embed
What would you like to do?
<?php
function create($values){
?>
<h3>
<?= $values['name'] ?>
</h3>
<p>
<?= $values['desc'] ?>
</p>
<?php
}
?>
<?php
require_once('ViewManager.php');
$view = new ViewManager();
$view->injectContent('home',
array(
'name' => 'A website!',
'desc' => "Lorem ipsum dolor...."
)
);
?>
<?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
You can’t perform that action at this time.