2014-07-10 85 views
0

我有PHP 5.5.9和我激活php_intl.dll exyention並在活動php.ini中設置其配置如下:如何安裝twig localizeddate過濾器?

[intl] 
intl.default_locale = ar 
; This directive allows you to produce PHP errors when some error 
; happens within intl functions. The value is the level of the error produced. 
; Default is 0, which does not produce any errors. 
;intl.error_level = E_WARNING 

當我嘗試下面的樹枝代碼:

{{ item.get_date('j F Y | g:i a')|localizeddate('medium', 'none', locale) }} 

我有一個致命的錯誤:

Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'The filter "localizeddate" does not exist in "index.html" at line 53' in

的官方文檔there不顯示如何安裝或該過濾器添加到枝杈。我使用沒有Symfony的簡單PHP應用程序。樹枝版本1.16.0

回答

1

您正在尋找twig/extensions composer軟件包,github回購協議爲fabpot/Twig-extensions

你提到你使用樹枝獨立,那麼你必須有一個Twig_Environment對象。它有一個addExtension方法,您需要調用它,傳遞一個Intl擴展的新實例:

$env->addExtension(new Twig_Extensions_Extension_Intl()); 
相關問題