smartyベースアプリケーションソース

1847 ワード

index.php
<?php
/*	//         
//     
define('SMARTY_DIR','D:/APMServ5.2.6/www/htdocs/smartydemo/smarty/');
require(SMARTY_DIR.'smarty.class.php');
//  
$smarty = new Smarty;
$smarty->compile_dir = SMARTY_DIR.'templates_c/';
$smarty->cache_dir = AMARTY_DIR.'cache/';
$smarty->template_dir = 'templates/';
$smarty->config_dir = 'config/';

$this->caching = true;
//    
$smarty->assign('name', 'phf');
//      
$smarty->display('index.tpl');
//$smarty->display('index.tpl', 2);	//    
*/
/* //       
$file = $smarty->fetch('index.tpl');
echo $file;
*/
/*
//     cache    
$smarty->caching = 2; // lifetime is per cache
$smarty->cache_lifetime = 300;
$smarty->display('index.tpl');
*/

//             
require_once('smartydemo.class.php');
$smarty = new Smarty_demo;
$smarty->assign('name', 'phf');
//$smarty->display('index.tpl');
$smarty->display('index.tpl', 2);

smartydemo.class.php
<?php
//
define('SMARTY_DIR','D:/APMServ5.2.6/www/htdocs/smartydemo/smarty/');
require(SMARTY_DIR.'smarty.class.php');

class Smarty_demo  extends Smarty
{
	function __construct()
	{
		Smarty::__construct();
		
		$this->compile_dir = SMARTY_DIR.'templates_c/';
		$this->cache_dir = SMARTY_DIR.'cache/';
		$this->template_dir = 'templates/';
		$this->config_dir = 'config/';
		
		$this->caching = true;
		$this->cache_lifetime = 1;
		$this->assign('app_name','smartydemo');		
	}
}

index.tpl
{* smarty *}
<h1>{$app_name}</h1>

hello {$name}!;