Custom Search

News World

Oct 2, 2012

Web Developer :: Smarty Alternatives

For most people who need a PHP templating system, Smarty is the natural choice mainly because of its popularity. As you probably know, Smarty is not the only PHP template engine in the market, but it is the most complete and reliable one.

From the variety of other PHP template engines, we would mention the following:
  • PHP Savant: http://phpsavant.com/yawiki/
  • PHPlib: http://phplib.sourceforge.net/
  • Yats: http://yats.sourceforge.net/
  • FastTemplate: http://www.thewebmasters.net/php/FastTemplate.pHTML
  • SimpleTemplate: http://simplet.sourceforge.net/
  • Yapter: http://yapter.sourceforge.net/
  • patTemplate: http://www.php-tools.de/site.php?file=/patTemplate/ overview.xml

Most of these PHP templating systems have a few advantages like speed and ease of use, mainly because they are not as complex as Smarty. However Smarty has more features than most of its competitors and it can be customized to be pretty fast.
In my opinion, the true competitor of Smarty is PHP Savant, which is a powerful but lightweight object-oriented template system for PHP. Savant includes a lot of Smarty's features.
However, there is one big difference between Smarty and Savant that can be either an advantage or a big disadvantage for Savant, depending on which point of view you are looking at.

The difference is that templates in Savant are written in PHP and not in another language like Smarty introduces. This can be:
  • An advantage for Savant—Designers work with PHP as a template language, they don't have to learn another templating language.
  • A disadvantage for Savant and a huge advantage for Smarty concerning security. Savant doesn't compile the templates into PHP as the templates themselves are PHP files. This way, designers have access to the full power of PHP. If the designer is not a trusted one Savant is out of the question and Smarty is the answer.


In most cases, designers are not trusted to have access to the systems where web pages run, therefore Smarty is still the best templating system for PHP. Savant is nice, but it almost totally lacks security, while other template engines have only some parts of the functionality Smarty has.


A Rough Guide to the Software Design Process
The process of building a website involves a few steps that may vary from project to project, but generally it is the same for most projects.

The first step is to establish the customer needs, on which you design a database. These needs are later transcribed in a spoken agreement or preferably in a document. This document should contain a description of the desired functionality of the software as well as the definition of the database tables with explanations for every column. Once the customer agrees on this document and maybe makes a few changes, you can start the actual process of building the website.

If you are your own customer this is not the case, otherwise it is my strong opinion that you should do this. For one of my first projects, I skipped the document part and it led to a total fiasco. The customer wanted more and more and did not want to pay more for it, but if the document had existed he would have had no choice.

The next step is to create and show a few layouts to the customer. This is the designer's job. He or she will work with the customer and come up with a design that the customer likes. After the customer finalizes a design, the actual building of the website begins. When the project is finished, the customer has a testing period in which a few modifications are made or some bugs cleared, and it's done.

This is beautiful in theory, but in real life, programmers speak languages like PHP and SQL and designers speak in HTML and CSS, and they often tend to have a few differences.


Working in Teams: Layers and Separation of Concerns
When human interactions might fail, it's preferable to separate the work as much as possible. Multi-tier software architecture should do the job. The most commonly used architecture is one with three tiers or layers.

These are:
  • Presentation Logic Layer
  • Business Logic Layer
  • Data Access Layer
Separating these layers in project development cycles allows you to achieve rapid application development with project maintainability in mind.
In the three-tier architecture, the interaction between layers is shown in the following diagram:





Starting from the bottom, at the Data Access Layer we find both the data and the ways to extract the data that we want to show to the user. The Data Access Layer may contain:
  • A database (MySQL, PostgreSQL, MSSQL, and so on) and the SQL language used to extract data from the database
  • Files that store data and PHP functions (or other languages) that parse the files
  • Data acquisition software (for example, a thermometer on the parallel port)
  • Now that we've extracted the data, we need to manipulate it in order to get the results we need to display. 
Data manipulation and validation is done at the Business Logic Layer, which may contain:

  • Data validation based on the business plan (for example, list only in-stock items)
  • Data manipulation according to the business plan (for example, discounts, stock liquidations, and so on)
  • Functions and formulas to calculate things like shipping expenses, and so on.

The Presentation Logic Layer is where the web page layout—how data from the Business Logic Layer is arranged in the web page—is defined. This is done using:

  • Web page templates
  • Text/CSS styles
  • Images, banners, and menu styles

Without a templating engine at the Presentation Logic Layer, we find HTML and PHP creating the layout with pure HTML and generating HTML code from PHP. In this case, we cannot divide the Presentation Logic and Business Logic layers into two separate layers, making the work of designers and programmers very difficult for complex software projects. That's where Smarty comes in.


No comments:

IT Conversations

Moneycontrol Latest News

Latest new pages on Computer Hope

Latest from Infoworld

Door Lock

Door Lock Import Top Door Lock from China Contact Quality Manufacturers Now