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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue