From 4566740b98ebcc58d36ca095ee20ebacf5567a4e Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Wed, 16 Jan 2013 09:03:27 +0000 Subject: backported r3253 to trunk/ --- framework/Web/THttpRequest.php | 2 ++ framework/Web/TUrlManager.php | 30 +++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'framework/Web') diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index 737bd4fa..133d0f2f 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -1320,6 +1320,7 @@ class TUri extends TComponent * The following enumerable values are defined: * - Get: the URL format is like /path/to/index.php?name1=value1&name2=value2... * - Path: the URL format is like /path/to/index.php/name1,value1/name2,value2... + * - HiddenPath: the URL format is like /path/to/name1,value1/name2,value2... * * @author Qiang Xue * @version $Id$ @@ -1330,5 +1331,6 @@ class THttpRequestUrlFormat extends TEnumerable { const Get='Get'; const Path='Path'; + const HiddenPath='HiddenPath'; } diff --git a/framework/Web/TUrlManager.php b/framework/Web/TUrlManager.php index b5a0a5be..5d96c973 100644 --- a/framework/Web/TUrlManager.php +++ b/framework/Web/TUrlManager.php @@ -44,6 +44,18 @@ class TUrlManager extends TModule * If {@link THttpRequest::setUrlFormat THttpRequest.UrlFormat} is 'Path', * the following format is used instead: * /entryscript.php/serviceID/serviceParameter/get1,value1/get2,value2... + * If {@link THttpRequest::setUrlFormat THttpRequest.UrlFormat} is 'HiddenPath', + * then entryscript.php will be hidden and the following format is used instead: + * /serviceID/serviceParameter/get1,value1/get2,value2... + * In order to use the 'HiddenPath' format you need proper url rewrite configuration; + * here's an example for Apache's .htaccess: + * + * Options +FollowSymLinks + * RewriteEngine On + * RewriteCond %{REQUEST_FILENAME} !-d + * RewriteCond %{REQUEST_FILENAME} !-f + * RewriteRule ^(.*)$ index.php/$1 [L] + * * @param string service ID * @param string service parameter * @param array GET parameters, null if not provided @@ -87,10 +99,16 @@ class TUrlManager extends TModule } } } - if($request->getUrlFormat()===THttpRequestUrlFormat::Path) - return $request->getApplicationUrl().'/'.strtr($url,array($amp=>'/','?'=>'/','='=>$request->getUrlParamSeparator())); - else - return $request->getApplicationUrl().'?'.$url; + + switch($request->getUrlFormat()) + { + case THttpRequestUrlFormat::Path: + return $request->getApplicationUrl().'/'.strtr($url,array($amp=>'/','?'=>'/','='=>$request->getUrlParamSeparator())); + case THttpRequestUrlFormat::HiddenPath: + return rtrim(dirname($request->getApplicationUrl()), '/').'/'.strtr($url,array($amp=>'/','?'=>'/','='=>$request->getUrlParamSeparator())); + default: + return $request->getApplicationUrl().'?'.$url; + } } /** @@ -110,7 +128,9 @@ class TUrlManager extends TModule { $request=$this->getRequest(); $pathInfo=trim($request->getPathInfo(),'/'); - if($request->getUrlFormat()===THttpRequestUrlFormat::Path && $pathInfo!=='') + if(($request->getUrlFormat()===THttpRequestUrlFormat::Path || + $request->getUrlFormat()===THttpRequestUrlFormat::HiddenPath) && + $pathInfo!=='') { $separator=$request->getUrlParamSeparator(); $paths=explode('/',$pathInfo); -- cgit v1.2.3