ZF-8444: AjaxContext always calls isXmlHttpRequest(), which may result in a fatal error | Fix sponsored by Enrise -

Issue Type: Bug Created: 2009-12-02T07:02:46.000+0000 Last Updated: 2011-06-09T08:39:08.000+0000 Status: Resolved Fix version(s): - 1.11.8 (07/Jul/11)

Reporter: Nico Edtinger (nico) Assignee: Dolf Schimmel (Freeaqingme) (freak) Tags: - Zend_Controller

Related issues: Attachments:


I have a controller with actions for normal webpages, AJAX callbacks and CLI calls. The AjaxContext helper is used for the AJAX callbacks. The CLI frontcontroller uses Zend_Controller_Request_Simple instead of Zend_Controller_Request_Http.

Now if I call the controller from CLI I get:

Fatal error: Call to undefined method Zend_Controller_Request_Simple::isXmlHttpRequest() in /.../Zend/Controller/Action/Helper/AjaxContext.php on line 71

AjaxContext should either check if the method is implemented or isXmlHttpRequest() needs to be added to Zend_Controller_Request_Abstract.


Posted by Ramon Henrique Ornelas (ramon) on 2010-11-29T00:37:30.000+0000

To this case I usually using Zend_Controller_Request_HttpTestCase.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2011-06-08T15:20:12.000+0000

Confirmed. Will fix asap.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2011-06-08T16:10:47.000+0000

Will commit later today (or tomorrow).


Index: tests/Zend/Controller/Action/Helper/AjaxContextTest.php

--- tests/Zend/Controller/Action/Helper/AjaxContextTest.php (revision 24040) +++ tests/Zend/Controller/Action/Helper/AjaxContextTest.php (working copy) @@ -32,6 +32,7 @@ require_once 'Zend/Controller/Action/HelperBroker.php'; require_once 'Zend/Controller/Front.php'; require_once 'Zend/Controller/Request/Http.php'; +require_once 'Zend/Controller/Request/Simple.php'; require_once 'Zend/Controller/Response/Cli.php'; require_once 'Zend/Layout.php'; require_once 'Zend/View.php'; @@ -197,6 +198,25 @@ $this->helper->initContext(); $this->assertNull($this->helper->getCurrentContext()); } + + /** + * @group ZF-8444 + */ + public function testAjaxContextIsRequestDependent() + { + $request = new Zend_Controller_Request_Simple(); + $helper = new Zend_Controller_Action_Helper_AjaxContext(); + + $helper->setActionController( + new Zend_Controller_Action_Helper_AjaxContextTestController( + $request, + $this->response, + array() + ) + ); + + $helper->initContext(); $this->assertTrue(true); // This will fatal error if it's wrong + } }

class Zend_Controller_Action_Helper_AjaxContextTestController extends Zend_Controller_Action

Index: library/Zend/Controller/Action/Helper/AjaxContext.php

--- library/Zend/Controller/Action/Helper/AjaxContext.php (revision 24040) +++ library/Zend/Controller/Action/Helper/AjaxContext.php (working copy) @@ -68,7 +68,10 @@ { $this->_currentContext = null;

  • if (!$this->getRequest()->isXmlHttpRequest()) {
  • $request = $this->getRequest();
  • if (!method_exists($request, 'isXmlHttpRequest') ||
  • !$this->getRequest()->isXmlHttpRequest())
  • { return; }

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2011-06-09T08:38:08.000+0000

Committed in r24130. Merged in r24131 with release 1.11 branch. Will be released in next mini release.

Have you found an issue?

See the Overview section for more details.


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