我正在使用Symfony構建一個簡單的應用程序。頁面佈局由一個帶有左右側欄的主體組成。側邊欄包含用戶可配置的幾個模塊。如何在symfony佈局中填充側邊欄內容?
symfony提供了這似乎是填充側欄的正確方法插槽:
layout.php中
<div id="left_sidebar">
<?php if (has_slot('left_sidebar')): ?>
<ul>
<?php include_slot('left_sidebar') ?>
</ul>
<?php else: ?>
<!-- default sidebar code -->
<?php endif; ?>
</div>
爲了填補我使用濾波器試圖槽。問題是,側邊欄中的一些模塊取決於動作(類別更新等)中發生的情況。所以他們應該在動作完成後生成。
msBootstrapFilter
class msBootstrapFilter extends sfFilter
{
public function execute($filterChain)
{
// Generating the sidebars at this point is TOO early
// as the content of some sidebars depends on the actions
// Execute next filter
$filterChain->execute();
// Generate the sidebars after running through all the code
// This is TOO LATE, the layout has been rendered
$this->generateSidebars();
}
}
我不想一個「跑欄」呼叫添加到每個行動似乎缺乏靈活性。
Symfony事件流中生成邊欄內容的最佳點是什麼?是否有適合的活動可以連接到?
謝謝你的迴應。我早些時候解僱了組件,它們不太適合我的目的。但是你的評論迫使我重新思考我的策略和追求的新路徑。 – Tramov 2010-11-22 15:40:21