a better way to handle custom routes?

#2
[eluser]GSV Sleeper Service[/eluser]
here's something I started working on a while back, I've abandoned it since, seeing as though CI provides pretty much everything I need.

Code:
$app_root = "/dev/test";

$pages = Array(
    '#^/(?:index\.(?:html|php))?$#'                           => 'page-index.php',       # main page handler
    '#^/brand/(\w+)?(?:/(\w+))?(?:/(\w+))?(?:/page(\d+))?#' => 'page-brand.php',       # brand handler
    '#^/item/([a-zA-Z0-9-]+)#'                                 => 'page-item.php',        # single item handler
    '#^/login.html#'                                      => 'page-login.php',       # login page handler
    '#^/register.html#'                                   => 'page-register.php',    # registration page handler
    '#^/logout.html#'                                     => 'page-logout.php'       # logout page handler
);

$parts = parse_url($_SERVER['REQUEST_URI']);
$path = preg_replace('#/+#', '/', $parts['path']); // drop multiple slashes
$path = str_replace($app_root,"",$path); // remove app_root from path

foreach ($pages as $page_pattern => $page) {
    echo $page_pattern.'<br />';
    if (preg_match($page_pattern, $path, $matches)) {
        echo "page match = $page<br />";
        print_r($matches);
        //require $page;
        //exit;
    }
}


Messages In This Thread
a better way to handle custom routes? - by El Forum - 03-25-2008, 03:24 AM
a better way to handle custom routes? - by El Forum - 03-25-2008, 06:06 AM
a better way to handle custom routes? - by El Forum - 03-25-2008, 07:29 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.