When creating a web application that has multiple pages, it is sometimes best to use server-side includes to accomodate common areas that will be used by all pages.
While optional, it is best to use templates to create the "shell" for each page that will be created. We will be using PHP server-side includes (SSI). SSI are external files that can contain PHP, HTML or both that get MERGED into a host page as though it was part of the original page when processed.
The advantage of using server-side includes instead of a normal template using Dreamweaver or another HTML editor is that all of the files based on a template that has been modified has to be uploaded to a server. In the case of PHP server-side includes, only the include files have to be updated and will affect all of the pages that has include links in them.
There are four flavors of PHP includes:
To include an external file, you use one of the include methods and pass it a path to an "include" file as its argument (e.g., include('include/header.inc.php'). Parentheses are optional but recommended. We will be using the require() method.
For a list of open source PHP templates, go to Smarty Template Engine.
Before you create the several side include files, it is best practice to start with an ordinary page that can be used as a model and then convert the common areas of that page to include files and link them back to the original file. The common areas will be used in all pages while new content will be used on a page-by-page basis.
<!doctype html>
<html>
<head> <meta charset="utf-8">
<title>Employee Directory</title>
</head>
<body>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Employee Directory</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Employee Directory</title>
<link rel="stylesheet" href="themes/EmployeeTheme.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style> /* Limit size of text input fields to 300px */ div.ui-input-text {width: 300px !important}
.error {color:red; font-weight:bold;}
</style>
</head>
<body>
<div data-role="page" id="home_page">
<div data-role="header">
<h1>Employee Directory</h1>
<a href="index.php" class="ui-btn ui-icon-home ui-corner-all ui-btn-icon-left">Home</a>
</div>
<div data-role="content">
<h2 class="ui-body ui-body-a ui-corner-all">PAGE TITLE</h2>
</div>
<div data-role="footer">
<h4>© 2015 by RMCS. All rights reserved.</h4>
</div>
</div>
</body>
</html>
After creating an ordinary file, you will want to organize your content in a folder to hold your include files that will be used by most pages. We will split the page into three sections:
<!doctype html>
<html>
<head>
<meta charset="utf-8"> <title>Employee Directory</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Employee Directory</title>
<link rel="stylesheet" href="themes/EmployeeTheme.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style> /* Limit size of text input fields to 300px */ div.ui-input-text {width: 300px !important}
.error {color:red; font-weight:bold;}
</style>
</head>
<body>
<div data-role="page" id="home_page">
<div data-role="header">
<h1>Employee Directory</h1>
<a href="index.php" class="ui-btn ui-icon-home ui-corner-all ui-btn-icon-left">Home</a>
</div>
<div data-role="footer">
<h4>© 2015 by RMCS. All rights reserved.</h4>
</div>
</div>
</body>
</html>
<div data-role="content">
<h2 class="ui-body ui-body-a ui-corner-all">PAGE TITLE</h2>
</div>
<?php require("includes/connection.inc.php")?> <?php require("includes/header.inc.php")?> <div data-role="content">
<h2 class="ui-body ui-body-a ui-corner-all">PAGE TITLE</h2>
</div> <?php require("includes/footer.inc.php")?>
We will first create the home page (index.php) from the template.php file.
While you could create each page as they are needed, it is best to create all of the pages UPFRONT. Also, it is best to create STATIC content first and then add DYNAMIC content afterward by adding recordsets, dynamic variables, repeat regions, etc.
File Name | Main Body Heading |
---|---|
employee_detail.php | EMPLOYEE DETAIL |
add_employee.php | ADD EMPLOYEE |
delete_employee.php | DELETE EMPLOYEE |
employee_search.php | EMPLOYEE SEARCH |
employee_login.php | EMPLOYEE LOGIN |
employee_registration.php | EMPLOYEE REGISTRATION |
edit_employee.php | EDIT EMPLOYEE |