The Controller Object

In this hour we focus on a particular implementation of the MVC pattern. The so-called front controller pattern places a single controller class at the heart of the system, where it fields requests, invokes commands, and dispatches views.

Although a controller object lies at the heart of our MVC system, it is also simple. Let’s take a look at one. Listing 24.1 shows a stripped-down controller object, called Controller.php. We are going to maintain a crude package system based on the directories that enclose our scripts. Controller.php belongs in the controller package.

Listing 24.1. The Controller Class
 1: <? 2: // controller/Controller.php 3: // qframe license: http://resources.corrosive.co.uk/pkg/qframe/license.txt ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.