smarty基础应用源码

6 篇文章 0 订阅

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}!;


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值