在Fedora 10上安装Smarty


1. 在Fedora 10上安装Smarty前准备,从官方网站上, 下载Smarty主程式,,
请注意需要PHP Version 4.0.6以上的版本才支持, 
http://www.smarty.net/download.php http://www.smarty.net/download.php

2. 将Smarty下载下来, 先放到/tmp目录下
# cd /tmp
# tar zxvf Smarty-2.6.25.tar.gz
# mkdir /var/www/smarty
# cp -R Smarty-2.6.25/libs/* /var/www/smarty/

3. 建立Smarty 所需的目录
# mkdir /var/www/smarty/templates
# mkdir /var/www/smarty/templates_c
# mkdir /var/www/smarty/cache
# mkdir /var/www/smarty/configs
# chmod 775 /var/www/smarty/templates_c
# chmod 775 /var/www/smarty/cache

4. 编辑test.php, 然后把下面程式存档
# cd /var/www/html
# vi test.php

<?php
require('/var/www/smarty/Smarty.class.php');
$tpl = new Smarty();
$tpl->template_dir = '/var/smarty/templates';
$tpl->compile_dir = '/var/smarty/templates_c';
$tpl->cache_dir = '/var/smarty/cache'; 
$tpl->config_dir = '/var/smarty/configs';
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
$tpl->assign('hello', 'Hello World');
$tpl->display('test.tpl');
?>

5. 编辑Smarty 的test.tpl, 然后把下面程式存档

$> vi /var/www/smarty/templates/test.tpl

<html>
<head>
<title>My First Smarty</title>
</head>
<body>
<{$hello}>
</body>
</html>

6. 打开Browser, 输入http://localhost/test.php , 就可以看到

Hello World

相关内容