PHP Classes
Icontem

File: test.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  >  CachedFastTemplate  >  test.php  
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
 

Contents

Class file image Download
<?php
// 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.
$tpl->define(
    array(
        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>";
    $tpl->read_from_cache($filename);
    $end = $tpl->utime();
    $runtime = ($end - $start) * 1000;
    echo "Completed in $runtime miliseconds<BR>\n";
    exit;
}

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

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

    $tpl->assign(
        array(
            NUMBER      =>  $Number,
            BIG_NUMBER  =>  $BigNum
        )
    );

    $tpl->parse(ROWS,".row");
}

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

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

$tpl->FastPrint();

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

?>

 
  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