Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7daa59028c
Fetching contributors…

Cannot retrieve contributors at this time

126 lines (105 sloc) 3.008 kb
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Ajax extends Controller_MOP {
public function action_index()
{
throw new HTTP_Exception_404('Ajax controller called without action. Check URL.');
}
/*
public function action_handleRequest($uri){
$subRequest = Request::Factory($uri);
$data = $subRequest->execute()->data();
$ajaxResponse = array(
'returnValue' => TRUE,
'response'=>$data
);
$this->response->body(json_encode($ajaxResponse));
}
*/
public function action_data($uri)
{
//request to child, just data
try {
$subRequest = Request::Factory($uri);
$data = $subRequest->execute()->data();
} catch (Exception $e) {
//return HTML from exception
$message = $e->getMessage() . $e->getTrace();
$ajaxResponse = array(
'returnValue' => FALSE,
'response' => $message
);
$this->response->body(json_encode($ajaxResponse));
return;
}
$ajaxResponse = array(
'returnValue' => TRUE,
'response'=>$data
);
$this->response->body(json_encode($ajaxResponse));
}
public function action_html($uri)
{
try {
$subRequest = Request::Factory($uri);
$html = $subRequest->execute()->data();
} catch (Exception $e) {
//return HTML from exception
$message = $e->getMessage() . $e->getTrace();
$ajaxResponse = array(
'returnValue' => FALSE,
'response' => $message
);
$this->response->body(json_encode($ajaxResponse));
return;
}
$html = $subRequest->execute()->body();
$cssResources = array();
array_push($cssResources, $this->resources['librarycss']);
array_push($cssResources, $this->resources['css']);
$jsResources = array();
array_push($jsResources, $this->resources['libraryjs']);
array_push($jsResources, $this->resources['js']);
$ajaxResponse = array(
'response'=>array(
'html'=>$html,
'js'=>$jsResources,
'css'=>$cssResources
),
'returnValue' => TRUE,
);
$this->response->body(json_encode($ajaxResponse));
}
public function action_compound($uri)
{
try {
$subRequest = Request::Factory($uri);
$requestResponse = $subRequest->execute();
} catch (Exception $e) {
//return HTML from exception
$message = $e->getMessage() . $e->getTrace();
$ajaxResponse = array(
'returnValue' => FALSE,
'response' => $message
);
$this->response->body(json_encode($ajaxResponse));
return;
}
$cssResources = array();
array_push($cssResources, $this->resources['librarycss']);
array_push($cssResources, $this->resources['css']);
$jsResources = array();
array_push($jsResources, $this->resources['libraryjs']);
array_push($jsResources, $this->resources['js']);
$compoundResponse = array(
'data' => $requestResponse->data(),
'html' => $requestResponse->body(),
'css' => $cssResources,
'js' => $jsResources,
);
$ajaxResponse = array(
'returnValue' => TRUE,
'response'=>$compoundResponse
);
$this->response->body(json_encode($ajaxResponse));
}
} // End Welcome
Jump to Line
Something went wrong with that request. Please try again.