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 splitt开发者_如何学编程ing and calling of controllers/methods accordingly to the URI?
Thanks a lot for your help!
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.
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.
精彩评论