2009年6月25日星期四

[fw-mvc] _forward() and custom context in contextSwitch

I have a custom context that is working fine -- except after I call _forward
to move from one action to another. I get the following error:

Error: Context "webwidget" does not exist

It does in fact exist, and works fine when not calling _forward. I can call
/mycontroller/flickr/format/webwidget and it works fine. But if I call
/mycontroller/tag/format/webwidget I get the "Context 'webwidget' does not
exist" error. So my question is, does calling _forward not load any custom
contexts that I have declared? How to I get this to work? Any ideas?

My controller looks like this (simplified):

---------------------------------------------------------------

public function init()
{
$contextSwitch = $this->_helper->getHelper('contextSwitch');
$contextSwitch->addContext('html', array());
$contextSwitch->addActionContext('flickr', array('json',
'webwidget'));
$contextSwitch->setAutoJsonSerialization(false);
$contextSwitch->initContext();
}

public function tagAction()
{
... do some stuff ...
$params['format'] = 'webwidget';
$this->_forward('flickr', $controller = null, $module = null, $params);
}

public function flickrAction()
{
... do some stuff ...
}

---------------------------------------------------------------

My custom context looks like this:

---------------------------------------------------------------

class Myproj_Controller_Action_Helper_ContextSwitch extends
Zend_Controller_Action_Helper_ContextSwitch
{

public function __construct()
{
parent::__construct();

$webwidgetContextName = 'webwidget';
$webwidgetContexSpec = array(
'suffix' => 'webwidget',
'headers' => array('Content-type' => 'text/html'),
'callbacks' => array(
'init' => 'initWebwidgetContext',
'post' => 'postWebwidgetContext'
)
);
$this->addContext($webwidgetContextName, $webwidgetContexSpec);
}

public function initWebwidgetContext()
{
$layout = Zend_Layout::getMvcInstance();
if (null !== $layout) {
$layout->enableLayout(); // must enable layout because normally
they are disabled when switching context
$layout->setLayout('webwidget');
}
}

public function postWebwidgetContext() { }
}

--
View this message in context: http://www.nabble.com/_forward%28%29-and-custom-context-in-contextSwitch-tp24212567p24212567.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: