文档介绍:PHP之Smarty入门
最后我们整理一下整个 Smarty 程式撰写步骤:
Step 1. 加载 Smarty 模版引擎。
Step 2. 建立 Smarty 对象。
Step 3. 设定 Smarty 对象的参数。
Step 4. 在程式中处理变量后,再用 Smarty 的 assign 方法将变量置入模版里。
Step 5. 利用 Smarty 的 display 方法将网页秀出。
怎么安排你的程式架构
上面我们看到除了 Smarty 所需要的资料夹外(class 、 configs 、 templates 、 templates_c) ,更有两个资料夹: includes 、 modules 。其实这是笔者模仿 XOOPS 的架构所建立出来的,因为 XOOPS 是笔者所接触到的程式中,少数使用 Smarty 模版引擎的架站程式。所谓西瓜偎大边,笔者这样的程式架构虽没有 XOOPS 的百分之一强,但至少给人看时更有 XOOPS 撑腰。
includes 这个资料夹主要是用来放置一些 function 、 sql ?,这样在 就能将他们引入了,如下:
:
<?php
include "class/";
define(’__SITE_ROOT’, ’d:/appserv/web/demo’); // 最后没有斜线
// 以 的位置为基准
require_once "includes/";
require_once "includes/";
$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