Files
DomFramework/outputhtml.php
2014-03-24 19:44:34 +00:00

54 lines
2.0 KiB
PHP

<?php
/** DomFramework
@package domframework
@author Dominique Fournier <dominique@fournier38.fr> */
require_once ("output.php");
/** Display in HTML the datas provided, with the layout support */
class outputhtml extends output
{
/** Data is printed by viewClass->viewmethod, in the middle of $layout
title is put in the title of the HTML page
$replacement modify the result (it can do title too :
array ("{title}"=>"title to display")
@param mixed $data Data to display on the page
@param string|null $title Title to put on head of page
@param string|null $viewClass Class in views to use to display
@param string|null $viewMethod Method in the class in views
@param string|null $layout Layout file in views
@param array|null $replacement Replace the {key}=>value */
public function out ($data, $title = FALSE,
$viewClass = FALSE, $viewMethod = FALSE,
$layout = FALSE, $replacement = array())
{
@header("Cache-Control: no-store, no-cache, must-revalidate");
@header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
@header('Last-Modified: '.gmdate ('D, d M Y H:i:s').' GMT');
@header('Cache-Control: post-check=0, pre-check=0', false);
@header('Pragma: no-cache');
@header ("Content-Type: text/html");
$resView = $data;
if ($viewClass !== FALSE && $viewMethod !== FALSE)
{
require ("views/$viewClass.php");
$reflection = new ReflectionMethod ($viewClass, $viewMethod);
$resView = $reflection->invokeArgs (new $viewClass, array ($data));
}
if ($layout !== FALSE)
{
$layoutPage = file_get_contents ("views/$layout.html");
$resView = str_replace ("{content}", $resView, $layoutPage);
}
// Do the title replacement in the replacement structure
if (! isset ($replacement["{title}"]))
$replacement["{title}"] = $title;
foreach ($replacement as $key=>$val)
$resView = str_replace ($key, $val, $resView);
return $resView;
}
}