{{PHP}}Smarty进阶安装指南

进阶安装
这是基础安装的进阶,请先阅读基础安装文章。

稍微更灵活的方式是使用扩展类来安装Smarty和初始化。 代替反复地定义路径,赋同样的值等等,我们可以把这些操作放在一个地方进行。

我们新建一个目录/php/includes/guestbook/,并新建一个 setup.php文件。 在下面的例子中,我们假设/php/includes 目录已经在include_path中。 确定你已经进行这个配置,或者使用绝对路径。

Example 2.10. /php/includes/guestbook/setup.php

<?php

// load Smarty library
require('Smarty.class.php');

// The setup.php file is a good place to load
// required application library files, and you
// can do that right here. An example:
// require('guestbook/guestbook.lib.php');

class Smarty_GuestBook extends Smarty {

function __construct()
{

// Class Constructor.
// These automatically get set with each new instance.

parent::__construct();

$this->setTemplateDir('/web/www.example.com/guestbook/templates/');
$this->setCompileDir('/web/www.example.com/guestbook/templates_c/');
$this->setConfigDir('/web/www.example.com/guestbook/configs/');
$this->setCacheDir('/web/www.example.com/guestbook/cache/');

$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
$this->assign('app_name', 'Guest Book');
}

}
?>

在index.php文件中使用setup.php:

Example 2.11. /web/www.example.com/guestbook/htdocs/index.php

<?php
require('guestbook/setup.php');

$smarty = new Smarty_GuestBook();
$smarty->assign('name','Ned');
$smarty->display('index.tpl');
?>

现在你可以看到这是非常简单就可以实例化一个Smarty的对象, 仅调用Smarty_GuestBook()就可以自动初始化程序。


转自:http://www.smarty.net/docs/zh_CN/installing.smarty.extended.tpl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值