I'm not that new to PHP, but I'm not that proficient, moreover, I would like to know the general practice that most PHP developers use when designing a website that generally has the same menus, but the content changes.

For all websites out there, how are these HTML/PHP scripts usually written?Would PEAR help at all?

Thank You so much for your time,cadmiumgreen::Byron M.

BerislavLopac
—
2005-06-10T08:17:37Z —
#2

This is a simple, basic implementation of the Front Controller pattern in PHP.

kyberfabrikken
—
2005-06-10T09:49:30Z —
#3

A big improvement over your design, would be to seperate controller (the switch-statement) from the view (the html-markup). This could be something like the following ;index.php

The Chain of Responsibility (classic Gang of Four) would offer greater freedom in this regard I think? For more on the CoR and an example (or two), do a search for 'Design Patterns Catelog' in this forum, for the thread I started

This method makes the content page less re-usable. It's bound to the common/header.php and common/footer.php files, which may or may not be OK. Why not just a simple function that contains the logic within the requested page.

And those functions would contain the extra data for extentions also, removing repeated code. THis isn't ideal but if I were going to make it simple, I'd probably start off with this and re-factor later to something better if needed. Personally, I usually create a class called StandardPage or something that handles all of that stuff. Then in the requested script (index.php, page.php etc.) I would instantiate it and customize as needed:

For simplicity, what I do is to read in the template file, looking for specific tags, which are replaced with dynamically generated content. So there isn't any PHP at all in the HTML, and this is for simple applications, web sites, etc where there is limited HTML fragments.

What I can't understand is why people have the need for putting PHP in a template file anyways? Why, in this day and age it still goes on I don't know as there isn't any excuse for it. But for what it's worth, PHP is not the only language that suffers from this

Anyways, end of nag (for the moment).

stereofrog
—
2005-06-10T14:50:00Z —
#8

cadmiumgreen said:

hello,

how common is it to use a 'skeleton' script?

A sample skeleton script that I'm using for some of my websites would look like this...

[snip]

Generally, try to avoid long spaghetti-style switch statement. In php the same can be expressed much clearer:

For simplicity, what I do is to read in the template file, looking for specific tags, which are replaced with dynamically generated content. So there isn't any PHP at all in the HTML, and this is for simple applications, web sites, etc where there is limited HTML fragments.

What I can't understand is why people have the need for putting PHP in a template file anyways? Why, in this day and age it still goes on I don't know as there isn't any excuse for it. But for what it's worth, PHP is not the only language that suffers from this Please, no offence, but haven't you paid any attention to all these PHP-is-already-a-template-engine debates?

Why, in this day and age it still goes on I don't know as there isn't any excuse for it.

PHP = template language + fuction library (+ some OO in PHP5)

system
—
2005-06-10T17:08:18Z —
#13

Yep but there is such a thing as layering, and separating those layers. It is surprising and disappointing to realise that there are developers out there, who use OO and design patterns every other day, and still put PHP in HTML.

but haven't you paid any attention to all these PHP-is-already-a-template-engine debates?

No offence taken, I sure have read all about PHP being a templating engine, but regardless of using either a prodecural or OO approach, to me it just doesn't fit well, to have PHP in HTML.

For example, just what are the overheads of replacing <bodycontentwouldgohere /> with the pregenerated HTML from elsewhere? None, basically Like, there must be about 101 different ways you could implement this sort of functionality?!

DougBTX
—
2005-06-10T17:11:27Z —
#14

So you're saying PHP is a bad language for the template layer? Even though that is what it was built for?

The first line of a PHP file starts with <?php, not #!, because of this.

Douglas

Viflux
—
2005-06-10T17:14:23Z —
#15

Dr Livingston said:

Yep but there is such a thing as layering, and separating those layers. It is surprising and disappointing to realise that there are developers out there, who use OO and design patterns every other day, and still put PHP in HTML.