开发者

Zend Framework : How can I have multiple instance of an Action Helper?

I’m building a widget system based on Action Helper. Each widget deal with the segment response to modify the render view. But , I’ve got a problem. The widgets are calling in a Controller Plugin, in the preDispatch, like this :

// $widgets : list of widget to call
foreach($widgets as $segment =>$widget) {
Zend_Controller_Action_HelperBroker::addHelper(
new $widget($segment));
}

That’s worsk fine. But if I’ve got a same widget call twice, the widget will be calling just one time. Example :

Zend_Controller_Action_HelperBroker::addHelper(
new Menu_Widget($segment=’menu’),
new Menu_Widget($segment =’right’),
);

If I do a dump to check the stack :

Zend_Debug::dump(Zend_Controller_Act开发者_运维知识库ion_HelperBroker::getStack());

I can see just one time Menu_Widget in this array.

How can I have multiple instance of a same Action Helper?

Sorry for my english.


IMO the helper broker is made just for that - to have only one instance. I would either extend the Broker (which makes little sense) or create a class that will handle the calls.

Update: Make a action/view helper. Assign widgets to it and then use it to echo the widgets.

// controller
foreach ($this->_helper->widget->getWidgets() as $widget) {
    $widget->setVariablesToView();
}

//view
$this->widget()->getWidget('widgetName'); //view params already set
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜