PHP and OOP Templates

While using objects can greatly simplify your code and expedite development of a site, it has a number of limitations, as mentioned in Chapter 2, Object-Oriented Programming. One of the big problems you may encounter is how best to interlace PHP and HTML while promoting separation.

For example, I want every page of the site to use a dynamically created footer such as Last modified Saturday, May 25, 2001. However, the template for the page itself contains only HTML, and if I were to place PHP within it to generate the footer, it would not be executed because the object process merely reads in the HTML template, replaces certain values, and prints it all out to the browser. No PHP execution takes place.

In the index.php object ...

Get PHP Advanced for the World Wide Web: Visual QuickPro Guide 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.