Browse Source

No more relative urls by default, #16

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@129 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
master
pzinovkin 15 years ago
parent
commit
f9ef17a685
  1. 10
      app/Action.php
  2. 2
      app/FrontController.php
  3. 20
      classes/Env.class.php

10
app/Action.php

@ -41,16 +41,10 @@ abstract class Action
* Redirect * Redirect
* *
* @param mixed $url * @param mixed $url
* @param mixed $relative Default to true
*/ */
protected function redirect($url = null, $relative = true)
protected function redirect($url = null)
{ {
$url = ($url) ? $url : Env::getRequestUri();
if ($relative) {
$url = FrontController::getInstance()->getBaseUrl() . $url;
}
header('Location: ' . $url);
header('Location: ' . (($url) ? $url : Env::getRequestUri()));
exit(); exit();
} }

2
app/FrontController.php

@ -100,7 +100,7 @@ class FrontController
public function execute() public function execute()
{ {
try { try {
$request = Env::getRequestUri();
$request = Env::getRequestUri(true);
$route = $this->getRouter()->route($request); $route = $this->getRouter()->route($request);
if (!$route) { if (!$route) {
throw new Error404Exception('Route for "' . $request . '" not found'); throw new Error404Exception('Route for "' . $request . '" not found');

20
classes/Env.class.php

@ -14,22 +14,24 @@
class Env class Env
{ {
static protected $request = null;
static protected $request = array();
static protected $params = array(); static protected $params = array();
static public function getRequestUri()
static public function getRequestUri($trim_base = false)
{ {
if (self::$request === null) {
if (!isset(self::$request[$trim_base])) {
// removes get params // removes get params
list(self::$request, ) = explode('?', Env::Server('REQUEST_URI'));
// removes base url
$base = FrontController::getInstance()->getBaseUrl();
if (($length = strlen($base)) > 0 && strpos(self::$request, $base) === 0) {
self::$request = (string) substr(self::$request, $length);
list(self::$request[$trim_base], ) = explode('?', Env::Server('REQUEST_URI'));
if ($trim_base) {
// removes base url
$base = FrontController::getInstance()->getBaseUrl();
if (($length = strlen($base)) > 0 && strpos(self::$request[$trim_base], $base) === 0) {
self::$request[$trim_base] = (string) substr(self::$request[$trim_base], $length);
}
} }
} }
return self::$request;
return self::$request[$trim_base];
} }
static public function Get($key = null, $default = null) static public function Get($key = null, $default = null)

Loading…
Cancel
Save