|
Posted by Rik on 08/15/06 20:49
Chung Leong wrote:
> 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,
Pardon, 'reuse'? How many heads/closing html tags do you want in a page? I
normally opt for just one, but hey, that's silly me.
> 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.
Well, that's indeed a pro to the include.
However, a con is this: If I want to change something in the head once the
project is running, I usually don't want to fiddle around in files anymore,
I want to be able to change it in an interface. While a *.php page can just
be opened and displayed in an textarea, I'm definitely more at ease working
on the plain HTML bits.
Then again, my bigger projects all have a dynamically built head section,
little to no actual static HTML content there.
Grtz,
--
Rik Wasmus
[Back to original message]
|