iT邦幫忙

0

smarty 檔案位置問題

php

一般的作法,把 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 呢?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

8
fillano
iT邦超人 1 級 ‧ 2011-06-15 16:50:00
最佳解答

請參考: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/';
...
chan15 iT邦新手 3 級 ‧ 2011-06-15 17:02:01 檢舉

下絕對路徑是嗎

chan15 iT邦新手 3 級 ‧ 2011-06-15 17:02:40 檢舉

對了,那個 configs 做用是什麼

fillano iT邦超人 1 級 ‧ 2011-06-15 22:13:06 檢舉
  1. 簡單說,這些可以在runtime下設定,就看你怎麼用
  2. http://www.smarty.net/docsv2/en/config.files.tpl 然後看一下 http://www.smarty.net/docsv2/en/language.config.variables.tpl

我要發表回答

立即登入回答