HTML and CSS Reference
In-Depth Information
Setting Variables for the Header
In order to set the variables for the header, open index.php again and add the following code, shown in bold:
//-----------------------------------------------------------------------------
// Outputs the view
//-----------------------------------------------------------------------------
// Loads the <title> tag value for the header markup
$title = $controller->get_title();
// Sets the path to the app stylesheet for the header markup
$dirty_path = APP_URI . '/assets/styles/main.css';
$css_path = remove_unwanted_slashes($dirty_path);
// Includes the header, requested view, and footer markup
require_once SYS_PATH . '/inc/header.inc.php';
$controller->output_view();
require_once SYS_PATH . '/inc/footer.inc.php';
//-----------------------------------------------------------------------------
// Function declarations
//-----------------------------------------------------------------------------
The first variable— $title —is set using the get_title() method of the controller object.
Next, the stylesheet path is generated using the APP_URI constant and the path to the stylesheet, which is checked
for double slashes before being stored in $css_path for output.
ISN't thIS StYLeSheet path VarIaBLe OVerKILL?
at first glance, it might seem like the steps taken to generate the $css_path variable are unnecessary and that the uri
could easily be hard-coded into the header markup. after all, the file is always at assets/styles/main.css , right?
Because we're using uri-rewrites, we aren't able to use relative paths (i.e. href="./assets/styles/main.css" ).
using an absolute uri, such as href="/assets/styles/main.css" , is fine as long as the app is installed at the
root of the server.
however, if the app is installed in a subdirectory, the absolute uri needs to be edited to include the subdirectory
path, and we don't want to require editing of the header markup for every install.
as a result, putting together two lines of code to determine the absolute path of the stylesheet is a small effort to
avoid a big headache.
 
Search WWH ::




Custom Search