ForceContext Queries method twice?
Posted
by azz0r
on Stack Overflow
See other posts from Stack Overflow
or by azz0r
Published on 2010-04-14T16:21:33Z
Indexed on
2010/04/14
16:23 UTC
Read the original article
Hit count: 323
zend-framework
Hello,
I'm doing a per minute script, to output the xml that a server will read, I am used forceContext.
<?php
class My_Controller_Action_Helper_ForceContext extends Zend_Controller_Action_Helper_ContextSwitch {
public function initContext($format = null) {
$request = $this->getRequest();
$action = $request->getActionName();
$context = $this->getActionContexts($action);
//check if this is the only context
if(count($context) === 1) {
$format = $context[0];
}
return parent::initContext($format);
}
}
class Video_PerMinuteController extends Zend_Controller_Action {
function init() {
$contextSwitch = $this->_helper->getHelper('ForceContext');
$contextSwitch->addActionContext('transaction', 'xml')->initContext();
In my method, it gets the current minute count, adds 1, then saves. So I can clearly see when its accessed more than once in a minute.
If I comment out the second contextSwitch line, it only goes up 1, if Its not, it displays the xml page but adds 2 minutes (being called twice somehow).
Any ideas?
© Stack Overflow or respective owner