We Should Leverage PHP Frameworks More Than We Do PDF Print E-mail
Written by Joshua D Miller   
Friday, 01 May 2009 14:14

Why use a PHP framework at all?

One of PHP's chief advantages over other web languages (like Java) is its ease of implementation - especially in small or incremental projects. Simply by embedding 20 lines of PHP code within pre-existing HTML, one can have a running comment board, guest book, or contact form. On consulting engagements in which I recommend a Linux-Apache-MySQL-PHP (LAMP) stack, one question that often arises is "if you advocate PHP for our project for its simplicity, why add the overhead of an entire framework?" This is a valid question and deserves a few words.

The following are some of the many notable benefits of using any of the PHP frameworks.

Design Patterns. One major reason for using a framework in production PHP projects is that they enforce consistent use of good design patterns, such as the MVC and Front Controller patterns. A model-view-controller (MVC) architecture allows for complete separation of business logic from design/presentation logic, allowing for the modification of one without involving the other. A successfully-implemented MVC architecture should mean, for example, that the design team can completely re-design the website or webapp interface without the need of involving the programming/technical team. Similarly, the Front Controller design pattern implements a single entry script for all incoming requests. This reduces redundancy in application logic and works well with URL rewriting.

ORM. An absolute must for distributable web-based applications (whether commercial or open-source) is object-relational mapping (ORM) . At a high-level, this means creating language-specific objects (in this case PHP) that are translated on the backend to platform-independent database connectivity. In other words, if one has a table "Product" in their database, there is a PHP class to represent a Product (i.e. a record in the database) and the developer can interact with the object without needing to know any details about the database. Independent of the broader-based PHP frameworks that are the focus of this blog entry, both Doctrine and Propel are fantastic PHP ORM tools.

Speed of development. While it may seem counter-intuitive, the right framework can actually significantly speed up the development process. Through the use of helper classes and pre-built components, the vast majority of the most common legwork needed to accomplish a development task is already done for the developer by the framework. One example of this is support for forms; by defining as simple as a couple of PHP arrays or simple extensions to pre-existing framework classes, one can have a form display to the screen and create the code to retrieve and process the data. The best frameworks provide the flexibility, however, for as much or as little customization as the project demands.

AJAX & Web 2.0. Whether for better or for worse, web sites and web applications do not get very far in today's environment without a little snazziness. Making web applications behave like desktop applications as well as increasing their responsiveness and aestheic appeal is very much in vogue. The difficulty, however, is that there are only two options to accomplishing this: (1) writing low-level code or (2) implementing one of the myrias Ajax frameworks within your application. The best PHP frameworks have PHP wrappers for implementing Web 2.0 functionality such as drag and drop, effects, and asynchronous communication - all without writing any Javascript.

Templating. As mentioned in the Design Patterns discussion (above), a good PHP framework provides for the separation of design and development tasks.

PHP Frameworks


There are a few solid frameworks that incorporate all I have discussed above that are worth mentioning. Over the next few weeks, I will be writing reviews of each of them:

Zend Framework (http://framework.zend.com/): "Zend Framework is an open source, object oriented web application framework for PHP 5. ZF is often called a 'component library', because it has many loosely coupled components that you can use more or less independently. But Zend Framework also provides an advanced Model-View-Controller (MVC) implementation that can be used to establish a basic structure for your ZF applications."

Symfony (http://www.symfony-project.org/): "Symfony is a full-stack framework, a library of cohesive classes written in PHP5. It provides an architecture, components and tools for developers to build complex web applications faster. Choosing symfony allows you to release your applications earlier, host and scale them without problem, and maintain them over time with no surprise. Symfony is based on experience. It does not reinvent the wheel: it uses most of the best practices of web development and integrates some great third-party libraries."

CakePHP (http://www.cakephp.org/): "CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. Using commonly known design patterns like MVC and ORM within the convention over configuration paradigm, CakePHP reduces development costs and helps developers write less code." (from the CakePHP website)
Last Updated ( Monday, 11 May 2009 12:39 )
 

Open Source Projects Josh Supports :

   
Fedora Project   openSuSE Linux!   Ubutnu - Linux for Humans  Spread Firefox Affiliate