Smarty是非常流行的模板系統,它分離了業務和邏輯、執行速度快,在php網站中有廣泛的運用。
不過在部署到sina app engine(sae)上時出現了問題,因爲sae作爲雲計算平臺式無法進行文件讀寫操作的,所以Smarty中輸出的緩存文件就無法實現。
錯誤信息:“SAE_Fatal_error: Uncaught exception 'SmartyException' with message 'unable to write file ./web/templates_c/wrt4e95555280ef1' ”
SAE給出瞭解決方案就是使用Memcache。首先進入應用中的應用管理中,在服務管理中開啓Memcache一個初始化,
然後修改Smarty的配置文件:
// For SAE 編譯文件存放在memcache中
$smarty->compile_dir = 'saemc://smartytpl/';
$smarty->cache_dir = 'saemc://smartytpl/';
$smarty->compile_locking = false; // 防止調用touch,saemc會自動更新時間,不需要touch
上面三行是必須的。
這樣Smarty模板就可以在SAE上運行了。
轉自《Smarty For Sae | 勇之軌跡》(www.yongzhi.info)