使用自己的Smarty类

 利用Smarty的扩展设置(Extended Setup),通过扩展类和初始化Smarty环境,来安装Smarty。我们可以通过一种方法来取代重复设置目录路径、给相同的参数赋值。我在project目录下建立了include文件夹,并在其中建立 setup.php。(其实命名为smarty.lib.php更合适,它的目的是配置调用smarty库)

建立文件setup.php
<?php
// setup.php文件是个放置读取必需应用库文件的好地方
// 你可以像这样做,例如:
// require_once('project/include/setup.php');

class Smarty_w01f extends Smarty {

 function Smarty_w01f()
 {
 // Class Constructor.
 // 构造类,我用工作室给他命名:D
 // These automatically get set with each new instance.
 // 这些自动开始准备每一个实例

 $this->Smarty();
 $this->template_dir = './project/templates/';
 $this->compile_dir = './project/templates_c/';
 $this->config_dir = './project/configs/';
 $this->cache_dir = './project/cache/';
    
  // 如果你想修改Smarty的调用语法为{**},下面就可以
  //$this->left_delimiter = '{*';
  //$this->right_delimiter = '*}';

 $this->caching = true;
 }
}
?>


随之我要修改index.php
<?php
/*
file name:index.php
*/
define('SMARTY_DIR',str_replace("","/",getcwd()).'./libs/smarty/');
// 注意:Smarty有一个大写字母“S”
require_once(SMARTY_DIR . 'Smarty.class.php');
require_once('project/include/setup.php');

$smarty = new Smarty_w01f;

$smarty->assign('name','greengnn');
$smarty->display('index.tpl');

?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值