Chapter 7. Large-Scale PHP

In previous chapters, we explored techniques for writing highly maintainable, reusable, and reliable HTML, CSS, and JavaScript. In this chapter, we explore techniques for binding together these disparate technologies to assemble complete pages. To do this, we’ll look at a large web application in terms of two deceptively simple yet powerful abstractions: modules and pages. A module is a self-contained component of the user interface that encompasses everything needed (e.g., the HTML, CSS, and JavaScript) to make an independently functioning and cohesive unit that you can use in a variety of contexts across various pages. A page, from the point of view of this chapter, is the canvas responsible for assembling a collection of modules so that they work together within a single context.

This chapter presents PHP as the implementation language for classes to represent pages and modules in large web applications. However, as mentioned in Chapter 1, all of the concepts presented here are relatively easy to transfer to other object-oriented, server-side scripting languages as well. Object orientation provides a more structured, extensible alternative to building pages than using a purely procedural approach. Fortunately, PHP 5 (and to a lesser extent PHP 4) offers a rich set of object-oriented features. Object orientation is an important part of achieving Tenet 7, as well as Tenet 6, from Chapter 1:

Tenet 7: Pages are constructed from highly reusable modules that ...

Get Developing Large Web Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.