Skip to content

Instantly share code, notes, and snippets.

@rredpoppy
Last active March 28, 2016 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rredpoppy/5280239 to your computer and use it in GitHub Desktop.
Save rredpoppy/5280239 to your computer and use it in GitHub Desktop.
Simple view rendering function
<?php
define('VIEW_FOLDER', dirname(__FILE__) . '/views');
function renderView($viewName, $vars){
extract($vars);
ob_start();
require VIEW_FOLDER . "/$viewName.php";
$output = ob_get_contents();
ob_end_clean();
echo $output;
}
$data = array('name' => 'Adrian', 'does' => 'Php');
renderView('index', $data);
/**
index.php content
--------
<html>
<body>
Hello, <?php echo $name ?>! I hear you do <?php echo $does ?>?
</body>
</html>
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment