Issues and Work-Arounds
Using HTML Master Pages on a site that depends on PHP comes with certain easily remedied challenges.
Notice on the Stand-Alone Configuration walk-through tutorial page that we specifically do not map .php
files to HTML Master Pages. While you may certainly do so, you might find that the overhead this causes can generate suboptimal site performance and may even "break" some of your pre-existing PHP code; particularly anything that depends on:
- the
$_SERVER['PHP_SELF']
value which will always point at thedemuxer.php
file, usually with a concatenated path to the actual resource document, or - the
__FILE__
constant which will always point at theCresourceFile.php
source file.
The short explanation for this is that -- above all else -- HTML Master Pages is focused on providing a "pure HTML" Master Pages solution to web page authors who may have no interest in dynamic page generation, which is an important but under-served classification of web page authors. In order to extend access to the underlying PHP language for the more adventurous web page authors while still providing core Master Page merging capability, HTML Master Pages provides a very simple eval() wrapper around every file it loads whenever that file contains a <?php
tag. Using PHP in this way comes with some nontrivial processing overhead and the other minor nuisances listed above.
If you want to use PHP to dynamically construct your HTML documents, a well established best-practice exists which asserts a separation of your logic from your presentation code. When using HTML Master Pages, you can accomplish this by writing your classes and other business logic in .php
files, then place your dynamic, view-generating code into .phtml
files which are mapped to HTML Master Pages. Then, you need only direct web visitors to your:
-
.phtml
files for dynamic content (which willinclude
orrequire
your other.php
files, as needed), -
.html
or.htm
files for static content, but - never at your
.php
source files (unless you are using an alternative MVC pattern, which is explored elsewhere in this documentation).
Even with such well-separated code, you may still need an alternative to both $_SERVER['PHP_SELF']
and __FILE__
, which is $_SERVER['PATH_TRANSLATED']
. When the other values fail to give the value you need, try this one.