Zend modular website, action stack

How to create a modular website with a Zend card. I have pages in db, each page is represented as a url. Each page has the contents of 1toN. Each content has a controller, action and position (+ others are now not important columns). Thus, one request represents one page and several contents (several actions). How can I create all the actions before exiting? I would like to have a layout, for example, the example below, where the content is placed in containers (actions are performed before the layout is printed).

<div id="left">
   <?= $this->layout()->left_container ?>
</div>
<div id="center">
   <?= $this->layout()->center_container ?>
</div>
<div id="right">
   <?= $this->layout()->right_container ?>
</div>

So far I have called actions from the layout view, but I do not like this approach:

foreach ($contents as $item) {
    echo $this->action($item['action'], $item['controller'], null, array('content' => $item));
}

Thanks.

ps

adepretis , , , , . , ? , ...- > setResponseSegment, , .

p.s. # 2

, . , , , .

+3
3

. :

MyPlugin

class MyPlugin extends Zend_Controller_Plugin_Abstract
{

    public function routeStartup(Zend_Controller_Request_Abstract $request)
    {
        $action_stack = new Zend_Controller_Action_Helper_ActionStack();
        // here I will read actions from db and run it in loop, but for example few are staticly added bellow
        $action_stack->actionToStack('index', 'content', 'default', array('position' => 'left'));
        $action_stack->actionToStack('index', 'content', 'default', array('position' => 'center'));
        $action_stack->actionToStack('index', 'edo', 'default', array('position' => 'center'));
        $action_stack->actionToStack('left', 'edo', 'default', array('position' => 'left'));
        $action_stack->actionToStack('right', 'edo', 'default', array('position' => 'right'));
    }

}

BaseController,

class BaseController extends Zend_Controller_Action
{

    public function preDispatch()
    {
        $position = $this->_request->getParam('position', false);
        if ($position) {
            $this->_helper->viewRenderer->setResponseSegment($position);
        }
    }

}

.phtml

<div>
    <h2><u>LEFT:</u></h2>
    <?=$this->layout()->left?>
</div>
<div>
    <h2><u>CENTER:</u></h2>
    <?=$this->layout()->center?>
</div>
<div>
    <h2><u>RIGHT:</u></h2>
    <?=$this->layout()->right?>
</div>

, , - , , .

+1

ActionStack. :

class MyController_Action extends Zend_Controller_Action {
    function init() {
        /** you might not want to add to the stack if it 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');
    }
}

/somemodule/my/index /somemodule/somecontroller/left./somemodule/somecontroller/right,/somemodule/somecontroller/center, .

+1

, . , , . baseController . baseController, , :      ///baseController    modules/user/Controller/userController

?

0

Source: https://habr.com/ru/post/1703776/


All Articles