HTML and CSS Reference
In-Depth Information
// If the last element is empty, get rid of it
if (empty($uri_array[count($uri_array)-1])) {
array_pop($uri_array);
}
return $uri_array;
}
The parse_uri() function starts by removing the APP_FOLDER from the requested URI using preg_replace() ,
leaving only the bits that tell the app what the user is requesting. The function then uses explode() to split the URI up
at the forward slashes, then checks for empty elements at the beginning and end of the array before returning it.
Getting the Controller Name
Next, you need to figure out the name of the appropriate controller to load given the URI parts. To do this, add the
following bold code to index.php :
//-----------------------------------------------------------------------------
// Function declarations
//-----------------------------------------------------------------------------
/**
* Breaks the URI into an array at the slashes
*
* @return array The broken up URI
*/
function parse_uri( )
{
// Removes any subfolders in which the app is installed
$real_uri = preg_replace(
'~^'.APP_FOLDER.'~',
'',
$_SERVER['REQUEST_URI'],
1
);
$uri_array = explode('/', $real_uri);
// If the first element is empty, get rid of it
if (empty($uri_array[0])) {
array_shift($uri_array);
}
// If the last element is empty, get rid of it
if (empty($uri_array[count($uri_array)-1])) {
array_pop($uri_array);
}
return $uri_array;
}
 
Search WWH ::




Custom Search