修改文件http://www.aiiiq.com/smarttemplate/examples/basic/Hello_World.php<?php require_once "../../class.smarttemplate.php";
echo ('aaa');
$page = new SmartTemplate("Hello_World.html");
echo ('bbb');
$page->assign('TITLE', 'Hello World!');
$page->output();?>结果显示:
aaabbbSmartTemplate Compiler Error: Could not write compiled file.
echo ('aaa');
$page = new SmartTemplate("Hello_World.html");
echo ('bbb');
$page->assign('TITLE', 'Hello World!');
$page->output();?>结果显示:
aaabbbSmartTemplate Compiler Error: Could not write compiled file.
应该这样修改:
在类头部的外面加上这样一段:
$_CONFIG = array(
smarttemplate_compiled => "cache",
smarttemplate_cache => "cache",
);
还有这两个http://www.aiiiq.com/smarttemplate/tmp/是不是要删掉?<?php
class SmartTemplate
{
var $reuse_code = true;
var $template_dir = '';
var $temp_dir = 'http://www.aiiiq.com/smarttemplate/tmp/';
var $cache_dir = 'http://www.aiiiq.com/smarttemplate/tmp/';
var $cache_lifetime = 600;
var $cache_filename;
var $tpl_file;
var $cpl_file;
var $data = array();
var $parser;
var $debugger; function SmartTemplate ( $template_filename = '' )
{
global $_CONFIG; if (!empty($_CONFIG['smarttemplate_compiled']))
{
$this->temp_dir = $_CONFIG['smarttemplate_compiled'];
}
if (!empty($_CONFIG['smarttemplate_cache']))
{
$this->cache_dir = $_CONFIG['smarttemplate_cache'];
}
if (is_numeric($_CONFIG['cache_lifetime']))
{
$this->cache_lifetime = $_CONFIG['cache_lifetime'];
}
if (!empty($_CONFIG['template_dir']) && is_file($_CONFIG['template_dir'] . '/' . $template_filename))
{
$this->template_dir = $_CONFIG['template_dir'];
}
$this->tpl_file = $template_filename;
} function set_templatefile ($template_filename) { $this->tpl_file = $template_filename; }
function add_value ($name, $value ) { $this->assign($name, $value); }
function add_array ($name, $value ) { $this->append($name, $value); } function assign ( $name, $value = '' )
{
if (is_array($name))
{
foreach ($name as $k => $v)
{
$this->data[$k] = $v;
}
}
else
{
$this->data[$name] = $value;
}
} function append ( $name, $value )
{
if (is_array($value))
{
$this->data[$name][] = $value;
}
elseif (!is_array($this->data[$name]))
{
$this->data[$name] .= $value;
}
} function result ( $_top = '' )
{
ob_start();
$this->output( $_top );
$result = ob_get_contents();
ob_end_clean();
return $result;
} function output ( $_top = '' )
{
global $_top; // Make sure that folder names have a trailing '/'
if (strlen($this->template_dir) && substr($this->template_dir, -1) != '/')
{
$this->template_dir .= '/';
}
if (strlen($this->temp_dir) && substr($this->temp_dir, -1) != '/')
{
$this->temp_dir .= '/';
}
// Prepare Template Content
if (!is_array($_top))
{
if (strlen($_top))
{
$this->tpl_file = $_top;
}
$_top = $this->data;
}
$_obj = &$_top;
$_stack_cnt = 0;
$_stack[$_stack_cnt++] = $_obj; // Check if template is already compiled
$this->cpl_file = $this->temp_dir . preg_replace('/[:\/.\\\\]/', '_', $this->tpl_file) . '.php';
$compile_template = true;
if ($this->reuse_code)
{
if (is_file($this->cpl_file))
{
if ($this->mtime($this->cpl_file) > $this->mtime($this->template_dir . $this->tpl_file))
{
$compile_template = false;
}
}
}
if ($compile_template)
{
include_once ("class.smarttemplateparser.php");
$this->parser = new SmartTemplateParser($this->template_dir . $this->tpl_file);
if (!$this->parser->compile($this->cpl_file))
{
exit( "SmartTemplate Compiler Error: " . $this->parser->error );
}
}
// Execute Compiled Template
include($this->cpl_file); // Delete Global Content Array in order to allow multiple use of SmartTemplate class in one script
unset ($GLOBALS[_top]);
} function debug ( $_top = '' )
{
// Prepare Template Content
if (!$_top)
{
$_top = $this->data;
}
include_once ("class.smarttemplatedebugger.php");
$this->debugger = new SmartTemplateDebugger($this->template_dir . $this->tpl_file);
$this->debugger->start($_top);
} function use_cache ( $key = '' )
{
if (empty($_POST))
{
$this->cache_filename = $this->cache_dir . 'cache_' . md5($_SERVER['REQUEST_URI'] . serialize($key)) . '.ser';
if (($_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache') && ($_SERVER['HTTP_PRAGMA'] != 'no-cache') && @is_file($this->cache_filename))
{
if ((time() - filemtime($this->cache_filename)) < $this->cache_lifetime)
{
readfile($this->cache_filename);
exit;
}
}
ob_start( array( &$this, 'cache_callback' ) );
}
} function cache_callback ( $output )
{
if ($hd = @fopen($this->cache_filename, 'w'))
{
fputs($hd, $output);
fclose($hd);
}
return $output;
} function mtime ( $filename )
{
if (@is_file($filename))
{
return filemtime($filename);
}
} }?>
* Debugger Class
*
* @access private
*/
var $debugger;$_CONFIG = array(
smarttemplate_compiled => "http://www.aiiiq.com/smarttemplate/tmp/" /* temp_dir 编译临时文件目录 */,
smarttemplate_cache => "http://www.aiiiq.com/smarttemplate/tmp/" /* cache_dir 缓存目录 */,
cache_lifetime => 600 /* cache_lifetime 最小编译周期 */,
template_dir => "http://www.aiiiq.com/smarttemplate/" /* template_dir 模板目录 */
); /**
* SmartTemplate Constructor
*
* @access public
* @param string $template_filename Template Filename
*/
function SmartTemplate ( $template_filename = '' )
{
global $_CONFIG;
我这样改了以后,什么都不显示了,
SmartTemplate Compiler Error: Could not write compiled file.这句提示也没有了
var $temp_dir = './tmp/';
var $cache_dir = './tmp/';如果用绝对路径就不好用了
var $temp_dir = 'http://www.aiiiq.com/smarttemplate/tmp/';
var $cache_dir = 'http://www.aiiiq.com/smarttemplate/tmp/';是不是虚拟主机的问题啊?
smarttemplate_compiled => "cache",
smarttemplate_cache => "cache",
);
class SmartTemplate
{
好用http://www.aiiiq.com/smarttemplate/examples/basic/Hello_World.php
不好用啊
SmartTemplate Compiler Error: Could not write compiled file.
这个提示在说什么?
是不是每个目录都要有class.smarttemplate.php文件?<?php
/**
* set tmp dir
* @author zairwolfi
*/ $_CONFIG = array(
smarttemplate_compiled => "tmp",
smarttemplate_cache => "tmp",
);
/**
* SmartTemplate Class
*
* 'Compiles' HTML-Templates to PHP Code