Project Design

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am fairly new to PHP and have written an application for managing spam in
a quarantine like environment.

Now the problem has arisen that Branding will eventually come into the
picture as well as localisation.

I prefer to embed php code into the HTML segments of the page, the dynamic
PHP components having been populated by middleware classes that can take
care of all the business logic.

But now I am finding that it might be better to write classes that generate
blocks of HTML instead of having dynamic elements of PHP inside HTML.

What have other users experiences been like? Do you prefer to write
functions that generate HTML or do you prefer to have HTML blocks with PHP
in them?

Looking forward to reply's!

beep beep

Re: Project Design

Richard Stride wrote:
Quoted text here. Click to load it


I use a custom HTML template system, which allows me to write HTML
files (one for each page, or sub-section e.g. a news article template)
completely independently of the PHP code. The HTML contains
placeholders, e.g. or . I also have a switching
system, so that HTML sections can be blanked out conditionally. Might
look something like:

    <P>One paragraph.</P>
    <P>An alternative paragraph.</P>

I then have a function which parses the template file, and replaces the
placeholders with strings. So I can just call something like:

parseTemplate("home.html", array("USER_NAME" => $userName,
                                 "EMAIL_ADDRESS" => $email,
                                 "HEADLINE" => $headline,
                                 "BODY" => $newsBody,
                                 "IS_UGLY?" => true));

This may seem like a lot of work to set up, and overkill, and some
might say that it's inefficient at runtime. But from a maintainability
and clarity point of view, it's perfect. There's a sharp interface
between my PHP scripts and HTML design, it's immediately obvious what
variables are going where, and I can design the HTML and PHP completely
separately. And there's no messy nesting of HTML in PHP (so no escape
characters that reduce clarity) or vice versa.


Re: Project Design

Kimmo Laine wrote:
Quoted text here. Click to load it

Unless next_page.php generates PHP, the script with this include will
only get HTML.

Quoted text here. Click to load it


    if (isset($_GET['foo'])) {
      echo '<?php echo $_GET[\'foo\']; ?>';
    } else {
      echo '<?php echo \'Not available\'; ?>';

File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Site Timeline