Posted: Thu Nov 06, 2003 6:11 pm
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
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
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
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