forked from arraydude/copperFramework
/
ajax.php
63 lines (57 loc) · 1.37 KB
/
ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
require_once 'config.php';
/**
* Ajax Service Controller
*
* @author Nahuel Rosso
* @package copperFramework
* @version 1.2
*/
class Ajax {
private $model;
/**
* __construct
*
* The constructor camelize the method
* @param string $method
* @param array $params
*/
public function __construct($method, $params) {
$method = copperStr::camelize($method);
$this->model = copperConfig::get("model");
$this->$method($params);
}
/**
* testAjaxService
*
* Ajax method for test the service
*
* @param array $params
*/
public function testAjaxService(array $params) {
echo json_encode($params);
}
/**
* doAjaxError
*
* Response an ajax error
*
* @param string $msg
* @return false
*/
protected function doAjaxError($msg) {
$message = array('error' => true, "msg" => $msg);
echo json_encode($message);
return false;
}
}
try {
$Ajax = new Ajax($_REQUEST['method'], $_REQUEST['params']);
} catch (Exception $exc) {
$errLog = "Peticion ajax (";
$errLog .= $_REQUEST['method'] . " con params " . json_encode($_REQUEST['params']);
$errLog .= ") falla por excepcion: " . $exc->getMessage();
copperConfig::doError($errLog . " File: " . __FILE__ . ":" . __LINE__);
copperConfig::doError($exc->getTraceAsString());
echo json_encode(array("error" => true, "msg" => $exc->getMessage()));
}