diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-01-29 03:22:02 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-01-29 03:22:02 +0000 |
commit | 894a33d744ede7ec9977133e632279ed55976f4f (patch) | |
tree | 10807ac32660ea499881fd1476c8d2cf696bd1c5 /core/helpers | |
parent | ad82721c3b164438d01ecc28350d8168894512a8 (diff) |
Add support for pretty urls. So now instead of urls like:
http://example.com/gallery3/index.php/albums/2
http://example.com/gallery3/index.php/photos/9
You'll see urls like:
http://example.com/gallery3/index.php/Family/Weddings
http://example.com/gallery3/index.php/Family/Weddings/Bob.jpg
Diffstat (limited to 'core/helpers')
-rw-r--r-- | core/helpers/MY_url.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core/helpers/MY_url.php b/core/helpers/MY_url.php index fa358543..dd3682df 100644 --- a/core/helpers/MY_url.php +++ b/core/helpers/MY_url.php @@ -18,6 +18,36 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class url extends url_Core { + static function site($uri, $protocol=false) { + list($controller, $arg1, $args) = explode("/", $uri, 3); + if ($controller == "albums" || $controller == "photos") { + $uri = ORM::factory("item", $arg1)->relative_path(); + } + return parent::site($uri, $protocol); + } + + static function parse_url() { + if (Router::$controller) { + return; + } + + $count = count(Router::$segments); + foreach (ORM::factory("item") + ->where("name", Router::$segments[$count - 1]) + ->where("level", $count + 1) + ->find_all() as $match) { + if ($match->relative_path() == Router::$current_uri) { + $item = $match; + } + } + + if (!empty($item)) { + Router::$controller = "{$item->type}s"; + Router::$controller_path = APPPATH . "controllers/{$item->type}s.php"; + Router::$method = $item->id; + } + } + /** * Just like url::file() except that it returns an absolute URI */ |