The View

In KISSMVC, the aim of the View is to help separate of your application logic from the presentation.

The templates are plain PHP files, and so normal PHP code can be used and the PHP global variables are accessible together with any extra variables you have passed in as a parameter in the form of an associative array.

There are 4 very similar functions provided for the View:

<?php
//accepts a filename to the template
function viewDump($filename,&$vars=null) {
  if (
is_array($vars))
    
extract($vars);
  require(
APP_PATH.'views/'.$filename);
}

//as above, but returns the output as a string
function viewFetch($filename,&$vars=null) {
  if (
is_array($vars))
    
extract($vars);
  
ob_start();
  require(
APP_PATH.'views/'.$filename);
  return 
ob_get_clean();
}

//accepts a string as the template
function viewFetchStr($str,&$vars=null) {
  if (
is_array($vars))
    
extract($vars);
  
ob_start();
  eval(
'?>'.$str);
  return 
ob_get_clean();
}

//as above, but returns the output as a string
function viewDumpStr($str,&$vars=null) {
  if (
is_array($vars))
    
extract($vars);
  eval(
'?>'.$str);
}
?>