歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 在Fedora 10上安裝Smarty

在Fedora 10上安裝Smarty

日期:2017/2/28 16:44:56   编辑:Linux教程

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

Copyright © Linux教程網 All Rights Reserved