This repository was archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathRExtController.php
More file actions
69 lines (62 loc) · 1.55 KB
/
RExtController.php
File metadata and controls
69 lines (62 loc) · 1.55 KB
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
64
65
66
67
68
<?php
define("__BASE__", rtrim(str_replace(DS, "/", dirname($_SERVER["PHP_SELF"])), "/"));//Current App Directory
class RExtController extends RController {
/**
* Redirect to another action
*
* @param string $action Action name
* @param array $params Parameters that will be passed
* @param boolean $js Whether use javascript
*/
function redirect($action, array $params = array(), $js = false) {
$this->redirectUrl($this->path($action, $params), $js);
exit();
}
/**
* Redirect to another URL
*
* @param string $url URL
* @param string $js Whether use javascript
*/
function redirectUrl($url, $js = false) {
if ($js) {
echo '<script language="Javascript">window.location="' . $url . '"</script>';
exit();
}
header("location:{$url}");
exit();
}
/**
* Contruct a path from action name
*
* @param string $action Action name, like "update", "update.go"
* @param array $params Parameters
* @return string
*/
function path($action, array $params = array()) {
if (!strstr($action, ".")) {
$action = $this->name() . "." . $action;
}
$url = $_SERVER["PHP_SELF"] . "?action=" . $action;
if (!empty($params)) {
$url .= "&" . http_build_query($params);
}
return $url;
}
/**
* Determine if it is a POST request
*
* @return boolean
*/
function isPost() {
return ($_SERVER["REQUEST_METHOD"] == "POST");
}
/**
* Is from AJAX request?
*
* @return boolean
*/
function isAjax() {
return (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && $_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest");
}
}