PHP Classes
Icontem

File: richard_example.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jesus M. Castagnetto  >  Generalized CachedTemplate class  >  richard_example.php  
File: richard_example.php
Role: ???
Content type: text/plain
Description: Example using Richard's Template class
Class: Generalized CachedTemplate class
General Template Caching class
 

Contents

Class file image Download
<?php
/*
 * $Id: richard_example.php,v 1.3 2000/07/16 19:33:46 jesus Exp $
 */

/*
 * Based on "seperate.php" (sic) example file by R. Heyes
 * from the Template class package -- JMC
 */

require "class.template.inc";
require "./class.RHTemplateAdaptor.php";
require "./class.CachedTemplate.php";

$tpl = new CachedTemplate();
// no need to use $tpl->init(), because the 
// Template class has no constructor

// for benchmarking
$start = $tpl->utime();

$tpl->load_file('header', 'header-template.html');
$tpl->load_file('main', 'main-template.html');
$tpl->load_file('footer', 'footer-template.html');

// Check if we can send the cached file
if ($tpl->valid_cache_file()) {
	echo "<B>FROM CACHE</B>\n<BR>";
    $tpl->read_from_cache();
    $end = $tpl->utime();
    $runtime = ($end - $start) * 1000;
    echo "Completed in $runtime miliseconds<BR>\n";
	exit;
}

// otherwise process the templates with some data

/* data for the templates */
$test_var = 'Hello world!';
$page_title = 'Template Class';

$table_rows = array();
$table_rows[] = array( 'column_1' => 'This is column one on row one!',
					   'column_2' => 'This is column two on row one!',
					   'column_3' => 'This is column three on row one!'
					 );

$table_rows[] = array( 'column_1' => 'This is column one on row two!',
					   'column_2' => 'This is column two on row two!',
					   'column_3' => 'This is column three on row two!'
					 );

$tpl->register('header', 'test_var,page_title');

$tpl->parse('header');
$tpl->parse_loop('main', 'table_rows');

// get parsed document
$data = $tpl->getParsedDoc("header,main,footer");

// output the page
echo $data;

// for benchmarking
$end = $tpl->utime();
$runtime = ($end - $start) * 1000;
echo "Completed in $runtime miliseconds<BR>\n";

// we write the file at the end so this
// operation will not be counted in the benchmark
$tpl->write_to_cache($data);
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products