Skip to content

Instantly share code, notes, and snippets.

@jhartikainen
Created June 29, 2011 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhartikainen/1053718 to your computer and use it in GitHub Desktop.
Save jhartikainen/1053718 to your computer and use it in GitHub Desktop.
ZF controller plugin which fakes dojo.io.iframe requests into XMLHttpRequests
<?php
/**
* This plugin automatically converts requests made with GET parameter "dojo_io_iframe" into XMLHttpRequests
*
* This allows transparent handling of iframe transport requests with code that handles XHR requests, since they're
* both essentially the same anyway - only the transport is different.
*/
class Wantlet_Controller_Plugin_IframeRequestHandler extends Zend_Controller_Plugin_Abstract {
private $isIframe = false;
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
if($request->getQuery('dojo_io_iframe')) {
//hacky hack...
//Triggers Ajax mode handling in request, $request->isXmlHttpRequest()
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->isIframe = true;
}
}
public function dispatchLoopShutdown() {
if(!$this->isIframe) {
return;
}
//Wrap result in dojo.io.iframe requested format
$response = $this->getResponse();
$response->setBody(
'<html><body><textarea>' . $response->getBody() . '</textarea></body></html>'
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment