一般的作法,把 template、template_c 那些資料夾規劃在根目錄
然後在根目錄設一個 config.php,include smarty 的 library 使用
這樣在根目錄建立的檔案,譬如說 index.php 只要 include config.php
就可以使用 smarty 的功能 $smarty->display('index.html');
但如果多了一層資料夾,譬如說 test\test.php
然後在 test\test.php require_once '../config.php';
直接下 $smarty->display('test.html');
這樣的結構就會失敗,該如何實現不同資料夾套用同一套 smarty 呢?
請參考:http://www.smarty.net/docsv2/en/installing.smarty.basic.tpl最下方的Example 2.9
可以這樣指定相關路徑:
<pre class="c" name="code">
<?php
...
require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = '/web/www.example.com/guestbook/templates/';
$smarty->compile_dir = '/web/www.example.com/guestbook/templates_c/';
$smarty->config_dir = '/web/www.example.com/guestbook/configs/';
$smarty->cache_dir = '/web/www.example.com/guestbook/cache/';
...
下絕對路徑是嗎
對了,那個 configs 做用是什麼