Skip to content

Instantly share code, notes, and snippets.

@awrowse
Created May 12, 2013 20:00
Show Gist options
  • Save awrowse/5564709 to your computer and use it in GitHub Desktop.
Save awrowse/5564709 to your computer and use it in GitHub Desktop.
Simple PHP view renderer
<?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