Zend Framework:为控制器的每个操作添加数据到布局

发布于 2024-12-21 20:32:29 字数 219 浏览 3 评论 0原文

我正在编写一个 Web 应用程序,我需要在一个特定控制器的所有操作中返回/计算的所有数据,以将数据返回到布局(而不是视图)。

因此,在每个操作之后,需要将控制器变量传递给布局,以便布局可以使用它。

详细来说,我想将计算出的数据存储在head中的json中。

有人知道如何做到这一点吗? 我考虑过一个控制器插件,但我不知道如何访问所需的参数,而且我真的不想使用单例来完成这一切。

i am writing a web application and i need all the data returned/computed in all actions of one specific controller to return data to the layout (not the view).

So after each action, a controller variable needs to be passed to the layout so the layout can use it.

In detail, i want to store the calculated data in jSon in the head.

Any ideas anyone of how to do this?
I thought about a controller plugin but i have no idea of how to access the desired parameters then and i really don't want to use a singleton for all this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

臻嫒无言 2024-12-28 20:32:29

,此方法在每个操作之前执行

public function preDispatch() {
}

让我们使用,例如

public function preDispatch()
{
        //calculate something
        //this is an example
        if($this->getRequest()->getActionName()=="admin")
        {
            $this->_helper->layout->setLayout('admin');
        }
        else
        {
            $this->_helper->layout->setLayout('user');
        }
}

Let use, this method is executed before every action

public function preDispatch() {
}

for example

public function preDispatch()
{
        //calculate something
        //this is an example
        if($this->getRequest()->getActionName()=="admin")
        {
            $this->_helper->layout->setLayout('admin');
        }
        else
        {
            $this->_helper->layout->setLayout('user');
        }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文