HTML and CSS Reference
* Determines the controller name using the first element of the URI array
* @param $uri_array array The broken up URI
* @return string The controller classname
function get_controller_classname( &$uri_array )
$controller = array_shift($uri_array);
This function keeps it simple: the URI is passed by reference to the function, the first element is loaded into the
$controller variable, and then the first letter is capitalized and that value is returned.
■ using the ampersand ( & ) to pass a variable by reference means that the actions performed inside the function
affect the data passed to it not only within the function's scope but the scope from which the function is called as well.
What this means is that a URI of http://example.com/room/1234/ would be parsed as an array with the
The first element of the array—“room”—would be isolated, capitalized, and then returned, giving us this
return value of the get_controller_classname() function:
We'll go into how this return value will be used a little later in this chapter.
Avoiding Unwanted Slashes
Whenever you're dealing with URIs, there's always the possibility that URI parts will have leading or trailing slashes.
When these parts are combined, it can cause problems.
For example, a site's URI might be stored in a variable like so:
And if a link is set up to be relative to web root, it might be declared like this:
$services_link = '/services/';