The utility files
The util/main.php
file
<?php
// Get the document root
$doc_root = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT');
// Get the application path
$uri = filter_input(INPUT_SERVER, 'REQUEST_URI');
$dirs = explode('/', $uri);
$app_path = '/' . $dirs[1] . '/' . $dirs[2] . '/';
// Set the include path
set_include_path($doc_root . $app_path);
?>
The view/header.php
file
<!DOCTYPE html>
<html>
<!-- the head section -->
<head>
<title>My Guitar Shop</title>
<link rel="stylesheet" type="text/css" href="<?php echo $app_path ?>main.css" />
</head>
<!-- the body section -->
<body>
<header>
<h1>My Guitar Shop</h1>
</header>
<main>
Description
- General-purpose files like the tags.php file in figure above are often called utility files because they can be used by many applications.
- View files like the header.php and sidebar.php files in this figure are included by more than one of the other view files.
The view/sidebar.php
file
<aside>
<!-- These links are for testing only.
Remove them from a production application. -->
<h2>Links</h2>
<ul>
<li><a href="<?php echo $app_path; ?>">Home</a></li>
<li><a href="<?php echo $app_path . 'admin'; ?>">Admin</a></li>
</ul>
<h2>Categories</h2>
<ul>
<!-- display links for all categories -->
<?php foreach ($categories as $category) : ?><li>
<a href="<?php echo $app_path . 'catalog' . '?action=list_products' . '&category_id=' . $category['categoryID']; ?>">
<?php echo $category['categoryName']; ?></a>
</li>
<?php endforeach; ?>
<li> </li>
</ul>
</aside>
The view/sidebar_admin.php
file
<aside>
<h2>Links</h2>
<ul>
<li><a href="<?php echo $app_path; ?>">Home</a></li>
<li><a href="<?php echo $app_path . 'admin'; ?>">Admin</a></li>
</ul>
<h2>Categories</h2>
<ul>
<!-- display links for all categories -->
<?php foreach ($categories as $category) : ?>
<li>
<a href="<?php echo $app_path . 'admin/product' .
'?action=list_products' .
'&category_id=' . $category['categoryID']; ?>">
<?php echo $category['categoryName']; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</aside>
The util/footer.php
file
</main>
<footer>
<p id="copyright">© <?php echo date("Y"); ?> My Guitar Shop, Inc.</p>
</footer>
</body>
</html>
Back