implement AjaxAgent for AJAX-responses
This commit is contained in:
parent
1754d062df
commit
fa9842d964
4 changed files with 119 additions and 1 deletions
65
agents/toplevel/AjaxAgent.inc
Normal file
65
agents/toplevel/AjaxAgent.inc
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\agents\toplevel;
|
||||
|
||||
|
||||
/**
|
||||
* Agent to return a JSON-string used by AJAX.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AjaxAgent extends \hhu\z\agents\ToplevelAgent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
|
||||
{
|
||||
parent::__construct($request, $response, $log);
|
||||
|
||||
|
||||
$this->setLanguage($request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private function setLanguage(\nre\core\Request $request)
|
||||
{
|
||||
// Set domain
|
||||
$domain = \nre\configs\AppConfig::$app['genericname'];
|
||||
|
||||
// Get language
|
||||
$locale = $request->getGetParam('lang', 'language');
|
||||
if(is_null($locale)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load translation
|
||||
putenv("LC_ALL=$locale");
|
||||
setlocale(LC_ALL, $locale);
|
||||
bindtextdomain($domain, ROOT.DS.\nre\configs\AppConfig::$dirs['locale']);
|
||||
textdomain($domain);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
52
controllers/AjaxController.inc
Normal file
52
controllers/AjaxController.inc
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\controllers;
|
||||
|
||||
|
||||
/**
|
||||
* Controller of the AjaxAgent to return a JSON-string used by AJAX.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AjaxController extends \hhu\z\Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
parent::preFilter($request, $response);
|
||||
|
||||
// Set content-type
|
||||
$this->response->addHeader("Content-type: application/json; charset=utf-8");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Create the JSON-string.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
// LayoutName
|
||||
$fileName = ROOT.DS. \nre\configs\CoreConfig::getClassDir('views').DS. strtolower($layoutName).DS;
|
||||
// AgentName and Action
|
||||
if(strtolower($agentName) != $layoutName || !$isToplevel) {
|
||||
if(strtolower($agentName) != strtolower($layoutName) || !$isToplevel) {
|
||||
$fileName .= strtolower($agentName).DS.strtolower($action);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
1
views/ajax/ajax.tpl
Normal file
1
views/ajax/ajax.tpl
Normal file
|
|
@ -0,0 +1 @@
|
|||
<?=$intermediate?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue