我正在使用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