PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Jesus M. Castagnetto  >  CachedFastTemplate  >  test.php  >  Download  
File: test.php
Role: ???
Content type: text/plain
Description: Simple script showing the use of the CachedFastTemplate class
Class: CachedFastTemplate
Simple class extending CDI's Fastemplate Class
Author: By
Last change:
Date: 22 years ago
Size: 1,551 bytes


Class file image Download
// This test file is a simple modification of a
// sample file include in FastTemplate

require ("./class.FastTemplate.php3");
require ("./class.CachedFastTemplate.php");

$tpl = new CachedFastTemplate("./templates");

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

$filename = "yipeee.html";
// if the filename is empty, the class will use PHP_SELF

// the templates are distributed w/FastTemplate
// we need this definition first, so the new logic can
// detect if the templates have changed.
        main    => "main.tpl",
        table   => "table.tpl",
        row     => "row.tpl"

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

// Otherwise process the page
$tpl->assign( array( TITLE => "FastTemplate Test") );

for ($n=1; $n <= 3; $n++)
    $Number = $n;
    $BigNum = $n*10;

            NUMBER      =>  $Number,
            BIG_NUMBER  =>  $BigNum


$tpl->parse(MAIN, array("table","main"));

$data = $tpl->fetch();
$tpl->write_to_cache($filename, $data);


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

For more information send a message to info at phpclasses dot org.