Introducing MVC
The advantages of the MVC architecture are perhaps best illustrated by providing an
example of the problems that are sure to arise when it isn??™t implemented. Suppose
you??™ve recently launched a new Web site, only to find that it??™s soon inundated with
users. Eager to extend this newfound success, the project begins to grow in ambition
and, as a result, in complexity. You??™ve even begun to hire a few talented staff members
to help out with the design and development. Well aware of your shoddy design skills,
you??™re particularly keen for the designers to immediately begin an overhaul that will
602 CHAPTER 24 ?– MVC AND THE Z END F RAMEWORK
lead to a relaunch next month. Accordingly, you ask them to begin redesigning all of
the site??™s pages, many of which look like this:
// Include site configuration details and page header
INCLUDE "config.inc.php";
INCLUDE "header.inc.php";
// Scrub some data
$eid = htmlentities($_POST['eid']);
// Retrieve desired employee's contact information
$query = "SELECT last_name, email, tel
FROM employees
WHERE employee_id='$eid'";
$result = $mysqli->query($query, MYSQLI_STORE_RESULT);
// Convert result row into variables
list($name, $email, $telephone) = $result->fetch_row();
?>
Employee Name:
Email:
Telephone:
// Retrieve employee absences in order according to descending date
$query = "SELECT absence_date, reason
FROM absences WHERE employee_id='$eid'
ORDER BY absence_date DESC";
CHAPTER 24 ?– MVC AND THE Z END F RAMEWORK 603
// Parse and execute the query
$result = $mysqli->query($query, MYSQLI_STORE_RESULT);
// Output retrieved absence information
while (list($date, $reason) = $result->fetch_row();
echo "$date: $reason";
}
// Include page footer
INCLUDE "footer.
Pages:
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688