views:

45

answers:

2

Hi everybody,

I am looking for some help on how to create the sort of URL-rewriting CodeIgniter features for my own PHP pet application. I know that the .htaccess-file does one part of the magic, but how does a PHP file looks that handles the URL splitting and calling of controllers/methods accordingly to the URI?

Thanks a lot for your help!

+2  A: 

Here is a good tutorial on phpro.org:

Model View Controller MVC

You need to have a look at router class. Things will be much clear if you read entire tutorial.

Sarfraz
Thanks! Great link
Industrial
+1  A: 

In MicroMVC I do this to get the URL of the page:

function uri()
{
//The SERVER values to look for the path info in
$server = array('PATH_INFO', 'REQUEST_URI', 'ORIG_PATH_INFO', 'REDIRECT_URL');

// Try each server var for the page URL
foreach($server as $item)
{
    if( ! empty($_SERVER[$item]) AND $uri = trim($_SERVER[$item]))
    {
        // Remove the query string (if given)
        $uri = parse_url($uri, PHP_URL_PATH);

        if($uri)
        {
            return $uri;
        }
    }
}
}

You can also look at the gluephp project.

Xeoncross