Why Use a PHP Framework?

February 25th, 2010 Leave a comment 5 comments
Like the article?
PHP Frameworks

Frameworks for use in web development have been steadily gaining in popularity. Some web technologies, such as Ruby on Rails, are frameworks. Others, like CSS, are benefiting from the emergence of new frameworks like Blueprint CSS. There are a number of high quality frameworks for use with PHP. These frameworks bring a number of benefits to your PHP development. And it is these benefits that are why you should use a PHP framework.

Model-View-Controller (MVC)

Most PHP frameworks are based on the design pattern known as Model-View-Controller (MVC). This design pattern uses object oriented code to break a web application into modular pieces. The model handles the database portion of the application. The controller provides business logic. The view controls the actual HTML pages being rendered. On reason for using a PHP framework that follows MVC is that it creates cleaner, more modular code. It is much easier to make changes such as switching to a different database system when all the code of a component is in its own module. Without a PHP framework, it is easy for code to become disorganized or convoluted. There are so many ways to do the same task in PHP. Using a PHP framework helps provide a single way to handle many common tasks and that results in much cleaner code and easier maintenance.

Separate PHP from HTML

Speaking of maintenance, have you ever had to change a database connection string in some PHP code? If so, you may have had to look through and edit multiple files. Using a PHP framework enforces modular code which makes these types of maintenance tasks simple.

Web development has become much more complicated. Not too long ago, a web designer designed the graphics, wrote the HTML and developed an entire web site. Now web applications are made by teams of people with various skills. PHP frameworks that use MVC make this process much easier. A web designer can maintain the HTML templates without needing to know a lot of PHP or database code. Likewise, a database specialist can optimize queries in one place. Using a PHP framework makes collaborative web development far easier.

User-friendly URL Namespaces

Another reason you should use a PHP framework for your development, is that frameworks provide user-friendly URL namespaces. Most PHP frameworks utilize a routing or dispatcher class that maps URLs to classes and methods. This way you can avoid unwieldy URLs that include query strings. An added benefit of this is that your URLs will be more search engine friendly and you can add keywords to your URLs for some basic search engine optimization.

Rapid Development

The greatest benefit of using a PHP framework is the ability to rapidly develop web applications. A PHP framework will make your development time much more efficient. The framework already provides so many of the basic elements of a web application such as an interface to the database, sessions, URL mapping and more. By having these items already developed and tested, writing a new web application is greatly simplified. You may be surprised just how much faster using a PHP framework can be.

Top 5 PHP Frameworks

CodeIgniter

http://codeigniter.com

Codeigniter PHP Framework

CodeIgniter is the only PHP framework that boasts a very small footprint, designed for smaller PHP sites, possibly using shared-hosting providers and require the least amount of overhead to create full-featured PHP web applications.

Yii

http://www.yiiframework.com

Yii PHP Framework

Yii is a robust, modular PHP framework that is well-suited for developing large-scale Web applications. Yii comes standard with a full host of features, including MVC, ActiveRecord, caching, AJAX libraries, authentication and authorization components, input validation, Web services, and many more.

CakePHP

http://cakephp.org

CakePHP PHP Framework

CakePHP is a rapid application development PHP framework that provides an extensible architecture for developing, maintaining, and deploying PHP based web applications.

Zend

http://www.zend.com

Zend PHP Framework

Zend emphasizes flexible architecture and contains a host of addons, such as Zend Server, Zend Studio, and Zend Platform

Symfony

http://www.symfony-project.org

Symfony PHP Framework

Symfony advertises itself as a framework for enterprise applications. The framework seeks to provide a high degree of control over the configuration: from directory structure to external libraries, almost all parameters can be customized. Symfony is also bundled with a host of tools for testing, debugging and documentting a web application.

Conclusion

PHP frameworks can greatly simplify development. The framework enforces a number of design patterns that result in cleaner, more easily maintained code. It also speeds development and makes collaborative development a breeze. PHP frameworks also provide techniques for user and search engine friendly URL schemes. The biggest gain from using a PHP framework, however, is the huge boost in productivity. Developing an application using a PHP framework is many times faster. Considering the benefits, the real question should be why aren’t you using a PHP framework?

Help us spread the word!
  • Twitter
  • Facebook
  • LinkedIn
  • Pinterest
  • Delicious
  • DZone
  • Reddit
  • Sphinn
  • StumbleUpon
  • Google Plus
  • RSS
  • Email
  • Print
If you liked this article, consider enrolling in one of these related courses:
Don't miss another post! Receive updates via email!

5 comments

  1. charlie says:

    Great article. So by friendly url’s do you mean one doesn’t have to worry about regular expressions?

    • Michael Dorf says:

      Yes and no. The “no” is that your framework would be responsible for converting from a human-friendly URL, such as http://example.com/why-use-php-framework/ to http://example.com/?page_id=342 internally. The “yes” is that you almost certainly would still have to use regular expressions for custom redirects or URL changes.

  2. Mohammed says:

    Symfony is tooo slow , i dont prefer to work with it at all ,
    YII is the best choice between all php frameworks

  3. I always use PHP frameworks because it provides helpful techniques for developers and search engine friendly URL schemes.

  4. Lee Davis says:

    Thanks SO much for this article – having been the victim of a recent hack (enabled by my usage of un-audited code modules), I’m coming to realize that I’m going to need a framework that takes care of the security heavy lifting as well as remaining flexible and allowing import of custom front-end HTML/CSS and other custom coding. I tried desperately in the past to cobble “safe” ideas together, and, although I’d made my databases safer by using PDO, I was by no means ready for some of the other XSS I’ve recently experienced.

    I’ve decided I’m going with Codeigniter as it looks like the smallest learning curve with the most script types (from Facebook clones to custom CRUDs). I’d like to express to anyone reading this comment that there is no more “rolling your own” code security (unless you’re really, REALLY qualified) for sites and web applications now with a plethora of threats lurking in the wild. Using pre-fortified structures will DEFINITELY make it safer on the Web as the usage of code frameworks could help cut down on rife hackery by (at least) 20-40%…MAYBE.

Comment