HTML and CSS Reference
In-Depth Information
} else {
ini_set('display_errors', 0);
// Sets the timezone to avoid a notice
Because this app will utilize sessions to pass data between page loads, the script calls session_start() if the
$_SESSION superglobal isn't set.
Then, after loading the configuration variable, the script checks the DEBUG value and—if it's set to TRUE , which
should always be the case during development—turns on strict error reporting; otherwise, errors are suppressed.
Finally, because PHP throws a notice without it, the time zone is set using the APP_TIMEZONE variable.
Setting Up Utility Functions
To avoid clouding up the router's logic, complicated operations should be encapsulated in functions. Fortunately,
there aren't too many complicated operations in this section, so we'll need to create only four utility functions:
A function to parse the URI and return its parts as an array
A function to determine the controller name using the URI parts
A function to prevent the occurrence of double slashes in any part of a URI except its protocol
An autoloader that will check for classes within our app and include them (or provide a
helpful error message if the requested class doesn't exist)
Parsing the URI
Because we want our app to have pretty URIs and not awkward query strings, we'll need a way to determine which
parts of the URI are for configuration and which are simply part of the URI.
Because this app may not always be installed at the root of a uri, the parsing script needs to compare the uri
with the app's location and return only the parts of the uri that don't reference the app's location on the server.
For example, if the app is installed at , the uri for room id 1234 would be . however, if the app is installed in a subdirectory called realtime , the uri for
room id 1234 would be .
in both cases, we only want “room” and “1234” to be returned by the parse_uri() function.
The parts of the URI that aren't location-related will then be split apart at the forward slashes and stored as an
array for use with the app, which will use them to determine the view to be displayed (and a few other things that will
be covered later).
Search WWH ::

Custom Search