[PHP] Smarty-Lite 與 PHPSavant
前幾天在 gslin 看到 Smarty-lite ,剛剛看了一下,似乎比較適合單純 template engine 需求的使用者。
在 Why use Smarty-Light 可以看到 Lite 版主要的差異:
Smarty-Light has a few disadvantages, though.
Smarty-Light does not have all the features of Smarty, such as pre/post/output filters, include_php tag, php tag, section tag, security features, and error handling.
Smarty-Light plugins and templates are not compatible with Smarty.
Smarty-Light has no support for objects/classes. This was removed for speed. (Besides, classes in PHP4 are slow as hell to begin with.)
Smarty-Light has no support for template resources. This was removed for speed. (Besides, who wants to load a template from a database. That's also slow as hell.)
算是常用的 section tag 不能使用了,但還是可以用 foreach 來代替。
不過 Smarty-Light 不支援 objects/classes 就比較麻煩了,直接傳遞 objects/classes 能很方便的架構出 MVC 的模式。如果 objects/classes 不能用的話,也可以轉成陣列來替代。
最後一點挑釁味十足:
Smarty-Light has no support for template resources. This was removed for speed. (Besides, who wants to load a template from a database. That's also slow as hell.)
如果像 Movable Type 多人線上自訂 Template ,把 Template 存在資料庫做線上編輯或許是比較好的做法。當然也可以把 Template 做成檔案模式,只是有的時候統一由資料庫管理會比較好,主要還是看架構如何設計。
另外 gslin 提到的 PHPSavant,這裡有一篇跟 Smarty 的比較可以參考一下:
revjim.net : Smarty vs. PHPSavant
http://revjim.net/item/10170/
Paul M. Jones 回應 revjim.net :
http://paul-m-jones.com/blog/index.php?p=72
revjim 再回應:
http://revjim.net/comments/10171/
其它包含 PHPSavant 回應的文章:
http://www.oreillynet.com/pub/wlg/6029?page=last&x-order=date
http://www.phpguru.org/static/templating.html
註: PHPSavant 目前我還沒實際用過,等有空用過了再來寫心得。^^
PHPSavant 官方網址:
http://phpsavant.com