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.

How to use the KISSMVC View:

Say you have a template file named welcome.tpl.php with the following contents:

<html>
  <head>
    <title><?php echo $pagename;?></title>
  </head>
  <body>
    <h1>Welcome <?php echo $username;?>,</h1>
    <p>The time is now <?php echo date("Y-m-d H:i:s");?></p>
  </body>
</html>

This is how you use call template file using a simple function call:

<?php
$vars 
= array("pagename"="Welcome!","username"="Eric");
echo 
View::do_fetch("/path/to/welcome.tpl.php",$vars);

Same result as above, but using object-oriented methodology:

<?php
$vars 
= array("pagename"="Welcome!","username"="Eric");
$view = new View("/path/to/welcome.tpl.php",$vars);
echo 
$view->fetch();

Yet another way:

<?php
$view 
= new View("/path/to/welcome.tpl.php");
$view->set("pagename","Welcome!");
$view->set("username","Eric");
echo 
$view->fetch();