Php 如何在没有actionstack的情况下做到这一点

Php 如何在没有actionstack的情况下做到这一点,php,zend-framework,Php,Zend Framework,我在试图理解actionstack的功能以及为什么它们会如此糟糕时发现了这段代码。我认为actionstack只是一种类型的动作助手(就像flashmessenger、redirector或ViewRenderer) 但不管怎样,有人知道这段代码做什么,以及如何在没有actionstack的情况下做同样的事情吗 class MyController_Action extends Zend_Controller_Action { function init() { /**

我在试图理解actionstack的功能以及为什么它们会如此糟糕时发现了这段代码。我认为actionstack只是一种类型的动作助手(就像flashmessenger、redirector或ViewRenderer)

但不管怎样,有人知道这段代码做什么,以及如何在没有actionstack的情况下做同样的事情吗

class MyController_Action extends Zend_Controller_Action {
    function init() {
        /** you might not want to add to the stack if it's a XmlHttpRequest */
        if(!$this->getRequest()->isXmlHttpRequest()) {
            $this->_helper->actionStack('left', 'somecontroller', 'somemodule');
            $this->_helper->actionStack('center', 'somecontroller', 'somemodule');
            $this->_helper->actionStack('right', 'somecontroller', 'somemodule');
        }
}

class MyController extends MyController_Action {
    function indexAction() {
        // do something
    }
}

class SomecontrollerController extends MyController_Action {
    function leftAction() {
        // do something

        $this->_helper->viewRenderer->setResponseSegment('left_container');
    }

    function centerAction() {
        // do something

        $this->_helper->viewRenderer->setResponseSegment('center_container');
    }

    function rightAction() {
        // do something

        $this->_helper->viewRenderer->setResponseSegment('right_container');
    }
}

我将把这些操作作为重用小部件(带有
preDispatch()
方法的操作助手)来实现,如下所述:

小部件可以将输出呈现为
占位符
视图帮助程序,因此可以在布局中的任何位置使用

它们还可以将内容呈现到其他
占位符中,例如侧边栏,如手册中所述:

protected function _initSidebar()
    {
        $this->bootstrap('View');
        $view = $this->getResource('View');

        $view->placeholder('sidebar')
             // "prefix" -> markup to emit once before all items in collection
             ->setPrefix("<div class=\"sidebar\">\n    <div class=\"block\">\n")
             // "separator" -> markup to emit between items in a collection
             ->setSeparator("</div>\n    <div class=\"block\">\n")
             // "postfix" -> markup to emit once after all items in a collection
             ->setPostfix("</div>\n</div>");
    }
protected函数_initSidebar()
{
$this->bootstrap('View');
$view=$this->getResource('view');
$view->占位符('侧栏')
//“前缀”->要在集合中的所有项之前发出一次的标记
->setPrefix(“\n\n”)
//“分隔符”->要在集合中的项之间发出的标记
->设置分隔符(“\n\n”)
//“后缀”->要在集合中的所有项之后发出一次的标记
->setPostfix(“\n”);
}

另一种解决方案是使用视图帮助器,它访问模型数据,并在布局中运行它们。

我将作为重用小部件(带有
preDispatch()
方法的操作帮助器)实现这些操作,如下所述:

小部件可以将输出呈现为
占位符
视图帮助程序,因此可以在布局中的任何位置使用

它们还可以将内容呈现到其他
占位符中,例如侧边栏,如手册中所述:

protected function _initSidebar()
    {
        $this->bootstrap('View');
        $view = $this->getResource('View');

        $view->placeholder('sidebar')
             // "prefix" -> markup to emit once before all items in collection
             ->setPrefix("<div class=\"sidebar\">\n    <div class=\"block\">\n")
             // "separator" -> markup to emit between items in a collection
             ->setSeparator("</div>\n    <div class=\"block\">\n")
             // "postfix" -> markup to emit once after all items in a collection
             ->setPostfix("</div>\n</div>");
    }
protected函数_initSidebar()
{
$this->bootstrap('View');
$view=$this->getResource('view');
$view->占位符('侧栏')
//“前缀”->要在集合中的所有项之前发出一次的标记
->setPrefix(“\n\n”)
//“分隔符”->要在集合中的项之间发出的标记
->设置分隔符(“\n\n”)
//“后缀”->要在集合中的所有项之后发出一次的标记
->setPostfix(“\n”);
}

另一种解决方案是使用视图帮助器,它访问模型数据,并在布局中运行它们。

项目负责人关于实用ZF的另一篇伟大文章项目负责人关于实用ZF的另一篇伟大文章