Reply to Re: Is there a more efficient way to do this?

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация