php怎么安装模板_php 模板框架之smarty 的下载和安装
Smarty 官網:
http://www.smarty.net/
Smarty 下載:
https://github.com/smarty-php/smarty/releases/tag/v3.1.30
// 下載 tar.gz 放到你的網站服務器中,和 jQuery和 Bootstrap 配合使用。
Smarty 使用例程
// 假設 Smarty 框架已經解壓在 /var/www 目錄下,此目錄是apache2 的家目錄
// 現在,先寫一個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/"; // 指定臨時生成的網站目錄
$tpl->config_dir = __SITE_ROOT . "/configs/"; // 指定配置文件目錄
$tpl->cache_dir = __SITE_ROOT . "/cache/"; // 指定緩存目錄,這個目錄里面放著最終顯示的網站php 文件
$tpl->left_delimiter = '
$tpl->right_delimiter = '}>';
?>
// 創建一些文件夾
mkdir templates templates_c configs cache
// 編寫模板
// vim templates/test.htm
// index.php 調用該模板
// vim index.php
require "main.php";
$tpl->assign("title", "test");
$tpl->assign("content", "test_1");
// 上面兩行也可以用這行代替
// $tpl->assign(array("title" => "測試用的網頁標題", "content" => "測試用的網頁內容"));
$tpl->display('test.htm'); // 調用模板
?>
顯示效果:
總結
以上是生活随笔為你收集整理的php怎么安装模板_php 模板框架之smarty 的下载和安装的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 防火墙实验报告
 - 下一篇: 大智慧公式系统:指标公式