While it is known that separating
business logic from
design (presentation layer) is a good approach when your site (application) is getting large, sometimes it lacks the simplicity and also requires multiple pages beyond what are required.
It is known that there are some approaches to manage large sitedesign:
(a) Use template engine: Smarty or SeagullDocs:
http://seagull.phpkitchen.com/docs/wakka.php?wakka=HomePage There is also second-generation template method, derived from Smarty, like phpSavant:
http://www.phpsavant.com/yawiki/index.php?page=HomePage
(b) use xsl/css: like 'mosxml' engine.
(c) use special devised engine to do templating, like 'phpusql'.
(d) use template based on standard PHP instead of yet-another-heavy-object-oriented-something template engines. The reason is simply that PHP was originally designed as a templating language for rendering output from underlying C/C++ code. Therefore there is no need for 'double templating' using another template engine with its own syntax library.
(e) use special database-development framework like ColdFusion from Macromedia. Macromedia also has special template engine called 'Spectra' (only for large scale project).
(f) the most ideal GUI-method based on pattern-design is perhaps MVC method, but thus far its OOP method has lack implementation in PHP. [2] However, there is 'Template View' method, which is intended to use this 'OOP-standard' MVC method, see SimpleT discussed in: http://www.phpwact.org/pattern/template_view (vii) Beyond PHP, there is also known template engine like Cheetah.
I guess this requirement (separating business logic from design) could be interpreted in different ways, in accordance with your viewpoint. Whether the goal is to minimize complicated or sometimes overlapping tasks between designers and programmers, or to get maximum access-speed per page, or to introduce more flexibility to adapt to various presentation devices (mobilephone, web, palm, different browsers etc.) Therefore, I think it would be wise to define first what are the expected design goals.
Design goals
According to SeagullDocs, design goals (ideally) could be defined as follows:
- independence of data, logic & presentation layers
- extensible component architecture
- reduction of repetitive programming tasks
- simplifying data access
- comprehensive error handling
- module workflow routines
- form handling without the donkey work
- component reuse
- authentication management
- integration with PEAR libraries (optional)
- PHP coding standards
- platform/PHP version/browser independence
- self-generating documentation
- quality end user docs.
A good article on reasons to use template can be found at http://www.sitepoint.com/article/beyond-template-engine and sample of template is also given at http://www.sitepoint.com/examples/tempeng/template.zip What's interesting here is that the writer concludes: " the vast majority of template engines ...simply have it wrong," despite its intention to "
in theory, allows HTML designers with no PHP experience to modify the appearance of the site without having to look at any PHP code."
Apparently, the problem with template engine is that introducing new layer of code abstraction could affect significantly the access speed (let alone the multiple-pages required to describe each page). What's more is that it requires the developers and also designers to grasp at PHP and also template-engine syntax library, besides HTML/Javascript. This could be a source of problem if these teams are not always in near places.
In the same way, using special and proprietary database-development framework like ColdFusion from Macromedia could introduce simplicity to manage large sites, but 'sometimes' at the expense of speed. Therefore, if you use this method, caching is highly recommended.
Use PHP-standard library to design template
So, perhaps the best approach is to get back to the basics: use PHP own code library to define 'template'. An example is discussed in: http://www.sitepoint.com/article/beyond-template-engine Of course, using PHP-own standard library is not the best toy in town, but at least it could enable to use various PHP optimization method, which usually requires template in PHP-files (like PHP Accelerator, from www.php-accelerator.co.uk).
In this way, it seems that this approach to define template back in PHP own terms is quite similar to approach used by phpSavant (http://www.phpsavant.com/yawiki/index.php?page=HomePage). The best advantage of phpSavant is:
"
instead, it uses PHP itself as its template language so you *don't need to learn a new markup system."
Concluding note We have outlined here how the goal of separating business logic from presentation could be interpreted in various ways. However, the ultimate dream of 'excluding' coding from HTML-pages remains utopia, because sometimes the presentation-layer itself requires a bit coding. Perhaps the best approach to do so is to find a way to implement MVC method in PHP, like SimpleT :
(http://www.phpwact.org/pattern/template_view) The present note is not intended to review thoroughly the state-of-the-art of various templating-engines using PHP scripting, but instead to explore various possible approaches which can be used corresponding to different priorities and goals defined by the users.
So, what do you think, fellows?
Submitted at 4th Dec 2007
by funkee
This author can be reached at http://mysaltz.net/
email: vxianto@yahoo.com
First published in http://searchwarp.com/swa26830.htm (Nov. 26th, 2005).
References:
[1] Lozier, B.,"Beyond Template Engine," http://www.sitepoint.com/article/beyond-template-engine
[2] h ttp://www.phpwact.org/pattern/template_view
[3] Marston, T., "OOP for Heretics", http://www.tonymarston.net/php-mysql/oop-for-heretics.html
[4] SimpleT introducti on, http://simplet.sourceforge.net/
[5] "Enforcing Model-View separation in Template Engines", http://www.cs.usfca.edu/parrt/papers/mvc.templates.pdf
[6] for list of template engines using PHP:
http://www.phpwact.org/php/template_engines?DokuWiki=b5c5eb2e9545648e3dd2df53a78c1b2f
[7] for more complete list of template engines using PHP:
http://www.sitepoint.com/forums/showthread.php?threadid=123769
