Posted by Chung Leong on 08/15/06 19:51
Rik wrote:
> --page.php------------
> include('head.html');
> /* generate content */
> include('foot.html');
> ----------------------
Agh! Drives me crazy that people keep recommending this hamfisted
method. Doing includes in lieu of calling function is a poor way to
program. A page header or footer is not different from other
functionalities in your application. To reuse it, wrap it in a
function. Example:
--interface.php---
<?php function printHeader() { ?>
<html><head>...
<?php } ?>
<?php function printFooter() { ?>
....</body></html>
<?php } ?>
-----------------------
Note the immediate advantage here of having the HTML within the same
file. It's also obvious how you would implement any parameterized
behavior--by passing parameters. To handle different page title, for
example:
<?php function printHeader($title = "Home Page") { ?>
<html><head>
<title><?php echo htmlspecialchars($title); ?></title>
<?php } ?>
The individual pages then pass their own titles when they need to
override the default.
[Back to original message]
|