gpt4 book ai didi

php - 如何在 symfony 布局中填充侧边栏内容?

转载 作者:行者123 更新时间:2023-12-04 06:40:57 25 4
gpt4 key购买 nike

我正在使用 Symfony 构建一个简单的应用程序。页面布局由带有左右侧边栏的主体组成。侧边栏包含几个用户可配置的模块。

Symfony 提供的插槽似乎是填充侧边栏的正确方法:

布局.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>

为了填补我尝试使用过滤器的插槽。问题是侧边栏中的某些模块取决于操作中发生的情况(类别更新等)。所以它们应该在 Action 运行完成后生成。

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 事件流中生成侧边栏内容的最佳点是什么?是否有适合我可以连接的事件?

最佳答案

你可以使用一个组件吗?这基本上是一个带有某种 Action 的插槽。在您的操作中,您可以执行任何您的逻辑需要并以与上述相同的方式呈现它,但具有更多逻辑。

来自 manual :

A component is like an action, except it's much faster. The logic of a component is kept in a class inheriting from sfComponents, located in an actions/components.class.php file. Its presentation is kept in a partial. Methods of the sfComponents class start with the word execute, just like actions, and they can pass variables to their presentation counterpart in the same way that actions can pass variables.

关于php - 如何在 symfony 布局中填充侧边栏内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4246810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com