From 894a33d744ede7ec9977133e632279ed55976f4f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 29 Jan 2009 03:22:02 +0000 Subject: 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 --- core/helpers/MY_url.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'core/helpers') 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 */ -- cgit v1.2.3