ZF-3690: Cannot use both AjaxContext and ContextSwitch on same action

Description

We cannot use both the AjaxContext and ContextSwitch on the same action because one will cancel out the other as both would not have the same contexts. AjaxContext has the html context defined while the contextswitch doesn't resulting in an exception from contextswitch.

AjaxContext should trigger without contextswitch also triggering. Current workarounds are to add the context to both or change the format param for one....

$this->getHelper('ContextSwitch')->addContext('html', array());

Solutions: At lines 225, this code never returns because hasActionContext() calls hasContext($context, true) instead of hasContext($context, false)


        // Check if context allowed by action controller
        if (!$this->hasActionContext($action, $context)) {
            return;
        }

Comments

I had the same issue. Currently I try to not use both on an action: request it with ajax or request it as xml (atom feed).

I am encountering this same issue. My particular case can hopefully shine some light onto when this would be a problem:

In a fairly standard MVC setup, I have an action on a controller that generates a sitemap. It sets a variable with the Zend_Navigation object on the view. The sitemap can be viewed as html by administrators in a lightbox (an ajax request). The same sitemap can also be accessed as an xml document by search engine spiders.

There are obviously workarounds for my case, but a permanent solution via the framework itself is ideal.

The same problem! I have subclassed from ContextSwitch twice but cannot use this two classes in one controller.

The Framework Guide says: "First, it uses a different action controller property for determining contexts, $ajaxable. This is so you can have different contexts used for AJAX versus normal HTTP requests" - but it is not possible since one context class does not know about context defined it the other one.

Matthew, any intention to fix this one?