2011-05-30 76 views
1

哪個更好? View.yml爲每個模塊和/或動作 或 只是在視圖中添加use_javascript/use_stylesheet?Symfony view.yml vs use_javascript/use_stylesheet

我這麼問是因爲我聽到的view.yml較慢,但有些插件需要的view.yml包含所有JavaScript和樣式表(如合併和縮小)

回答

1

「,但有些插件需要的view.yml包含所有的javascript和樣式表(例如組合和縮小)「正確。爲了縮小使用view.yml是非常有用的。此外,我更喜歡使用view.yml,因爲我可以快速瀏覽模板正在使用的樣式表/ JavaScript。

只要您使用適當的緩存機制,view.yml不會變慢。它只是在開發它慢。記住,當你在生產環境中時,你改變了view.yml,直到你清除緩存纔會被更新。

讓我們看一個簡單的例子:

contractCreateSuccess: 
    javascripts: 
    - hint.js 
    - /jquery/js/jquery-1.4.2.min.js 
    - /jquery/js/jquery-ui-1.8.12.custom.min.js 
    - /jquery/plugins/ui.selectmenu.js 
    - /sfFormExtraPlugin/js/jquery.autocompleter.js 
    stylesheets: 
    - /jquery/css/Aristo/jquery-ui-1.8.7.custom.css 
    - /sfFormExtraPlugin/css/jquery.autocompleter.css 
    - /jquery/plugins/ui.selectmenu.css 

yourContractViewPrintSuccess: 
    layout: print 

agreementViewPrintSuccess: 
    layout: print 
contractUploadFileSuccess: 
    javascripts: 
    - /jquery/js/jquery-1.4.2.min.js 
    - /jquery/js/jquery-ui-1.8.12.custom.min.js 
    stylesheets: 
    - /jquery/css/Aristo/jquery-ui-1.8.7.custom.css 
    - /jquery/plugins/ui.selectmenu.css 
parnterCreateSuccess: 
    javascripts: 
    - /jquery/js/jquery-1.4.2.min.js 
    - /jquery/js/jquery-ui-1.8.12.custom.min.js 
    stylesheets: 
    - /jquery/css/Aristo/jquery-ui-1.8.7.custom.css 

我覺得這是更整潔,更容易比使用上述功能來讀取。 :-)

+0

需要什麼樣的緩存機制?我現在只是使用默認值,但也在探索支持APC的項目的sfAPCCache – Populus 2011-05-30 11:28:28