totally useless code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Above you have the $color, $dec, $key. These are the output vars ie the dynamic content which is slotted into the rest of a (static) html page.

Let's say you have class or a function which declares the vars (business logic) and stops right there, outputing a $page_vars array. Without all that html mucking up :wink: a nice php script, the logical flow is clearer.

Next, some separate presentation code could display the page. For html, that's as simple as writing "include('path/to/template.htm')". Template.htm would be a normal html file with some php echo's to print the dynamic page var bits. (Template engines work in a similar way but with custom placeholders which get swapped out or otherwise parsed).

Now an html designer can do their thing freely. He or she doesn't have to open up a scary php script and try and figure out what's going on.

Also, because you have a format-free $page_vars array, you can output the content in any way you like. Got to create some downloadable pdf's? No problem: pass the page vars into a pdf script. That's possibly the main benefit of separating out the presentation layer from the business logic layer: your code has become more flexible. It's not tied to a specific case and so it's easier to add new bongles to it.

Once you start thinking about application design, that inevitably leads into OOP & patterns - check out phppatterns.com
Post Reply