Created
December 17, 2011 18:18
-
-
Save gravataLonga/1490946 to your computer and use it in GitHub Desktop.
view system of MVC framework
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 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