Issues

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

Issue Type: Bug Created: 2008-07-20T01:28:39.000+0000 Last Updated: 2011-08-13T19:58:53.000+0000 Status: Open Fix version(s): Reporter: Geoffrey Tran (potatobob) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: Attachments:

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)

<pre class="highlight">
        // Check if context allowed by action controller
        if (!$this->hasActionContext($action, $context)) {
            return;
        }

Comments

Posted by Giorgio Sironi (giorgiosironi) on 2009-02-26T07:15:08.000+0000

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).

Posted by Court Ewing (courtewing) on 2009-10-12T07:50:11.000+0000

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.

Posted by Przemys?aw Wróbel (wrobel) on 2011-06-07T10:39:32.000+0000

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.

Posted by Pádraic Brady (padraic) on 2011-08-13T19:58:53.000+0000

Matthew, any intention to fix this one?

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts