Created
May 12, 2013 20:00
-
-
Save awrowse/5564709 to your computer and use it in GitHub Desktop.
Simple PHP view renderer
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 | |
/** | |
* Simple view render. | |
* | |
* @param String $view Path to View file | |
* @param Array $data Data to be passed to view | |
* @throws RuntimeException Thrown if message comes back blank | |
* | |
* @return String Rendered view (HTML) | |
*/ | |
protected function renderViewWithData($view, $data){ | |
ob_start(); | |
extract($data); | |
include $view; | |
$message = ob_get_clean(); | |
ob_end_clean(); | |
if(empty($message)){ | |
throw new RuntimeException(sprintf("View Renderer returned no data for view: %s", $view), self::ERROR_PAYLOAD_CONSTRUCT); | |
} | |
return $message; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment