From d327af5f481454d8738ab413e2c16ad829bbf800 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 26 Feb 2016 17:13:13 +0100 Subject: * friendly URL support --- app/php/application.xml | 34 +++++++++++++++++++++++---- app/php/url/UrlManager.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++ http/.htaccess | 10 ++++++++ 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 app/php/url/UrlManager.php create mode 100644 http/.htaccess diff --git a/app/php/application.xml b/app/php/application.xml index 4aa2f30..13a86e1 100644 --- a/app/php/application.xml +++ b/app/php/application.xml @@ -1,6 +1,7 @@ + @@ -9,9 +10,34 @@ EnableCache="true" /> - + + + + + + + + - + diff --git a/app/php/url/UrlManager.php b/app/php/url/UrlManager.php new file mode 100644 index 0000000..a33d98e --- /dev/null +++ b/app/php/url/UrlManager.php @@ -0,0 +1,57 @@ +_convertServiceParam($serviceParam), + preg_replace('#^/' . $serviceID . '#', '', $url) + ), + '/' + ) . '/'; + } + + public function parseUrl() { + $params = parent::parseUrl(); + if ($this->MatchingPattern) { + $serviceID = $this->MatchingPattern->ServiceID; + if (isset($params[$serviceID])) { + $params[$serviceID] = $this->_parseServiceParam($params[$serviceID]); + } + } + return $params; + } + + /** + * Convert service param from camelCase to hyphenated-form. + **/ + private function _convertServiceParam($param) { + return implode( + '-', + array_map('mb_strtolower', array_filter(preg_split('/(?=[A-Z])/', $param))) + ); + } + + /** + * Convert service param from hyphenated-form to camelCase. + **/ + private function _parseServiceParam($param) { + return implode( + '', + array_map('ucfirst', explode('-', $param)) + ); + } +} + +?> diff --git a/http/.htaccess b/http/.htaccess new file mode 100644 index 0000000..77ee952 --- /dev/null +++ b/http/.htaccess @@ -0,0 +1,10 @@ +RewriteEngine On + +RewriteCond %{REQUEST_FILENAME} !-d +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^(.*[^/])$ /$1/ [L,R=301] + +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ /index.php/$1/ [L] + -- cgit v1.2.3