php怎么安装模板_php 模板框架之smarty 的下载和安装
Smarty 官網(wǎng):
http://www.smarty.net/
Smarty 下載:
https://github.com/smarty-php/smarty/releases/tag/v3.1.30
// 下載 tar.gz 放到你的網(wǎng)站服務(wù)器中,和 jQuery和 Bootstrap 配合使用。
Smarty 使用例程
// 假設(shè) Smarty 框架已經(jīng)解壓在 /var/www 目錄下,此目錄是apache2 的家目錄
// 現(xiàn)在,先寫一個main.php
// main.php
include "smarty-3.1.30/libs/Smarty.class.php";
define ("__SITE_ROOT", "/var/www");
require_once('includes/include.php');
require_once('includes/functions.php');
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/"; // 指定模板目錄
$tpl->compile_dir = __SITE_ROOT . "/templates_c/"; // 指定臨時生成的網(wǎng)站目錄
$tpl->config_dir = __SITE_ROOT . "/configs/"; // 指定配置文件目錄
$tpl->cache_dir = __SITE_ROOT . "/cache/"; // 指定緩存目錄,這個目錄里面放著最終顯示的網(wǎng)站php 文件
$tpl->left_delimiter = '
$tpl->right_delimiter = '}>';
?>
// 創(chuàng)建一些文件夾
mkdir templates templates_c configs cache
// 編寫模板
// vim templates/test.htm
// index.php 調(diào)用該模板
// vim index.php
require "main.php";
$tpl->assign("title", "test");
$tpl->assign("content", "test_1");
// 上面兩行也可以用這行代替
// $tpl->assign(array("title" => "測試用的網(wǎng)頁標(biāo)題", "content" => "測試用的網(wǎng)頁內(nèi)容"));
$tpl->display('test.htm'); // 調(diào)用模板
?>
顯示效果:
總結(jié)
以上是生活随笔為你收集整理的php怎么安装模板_php 模板框架之smarty 的下载和安装的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 防火墙实验报告
- 下一篇: smarty 执行php,smarty模