Skip to content

Instantly share code, notes, and snippets.

@gravataLonga
Created December 17, 2011 18:18
Show Gist options
  • Save gravataLonga/1490946 to your computer and use it in GitHub Desktop.
Save gravataLonga/1490946 to your computer and use it in GitHub Desktop.
view system of MVC framework
<?php
// Function similar of MVC sistem
function view ( $file , $data = null){
// IF data different of null and diferrent than array
if($data!= NULL && !is_array($data)){
// Erro, expection.
throw new Exception('Data view isn\'t valid!');
return false;
}
$_html_ = ""; // Set a default html vars
// File exists ?!
if(!file_exists($file)){
// No, so trow new exception
throw new Exception($file . " file doesn't exists ");
return false;
}
// Buffer system are faster and more security than file_get_contents
ob_start();
// Extract data
extract($data);
// Call the file
require($file);
$_html_ = ob_get_contents(); // My content!
ob_end_clean();
return $_html_; // return html
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment