Wednesday, April 18, 2012

Powerful but light PHP Framework/Library combination : Slim, Twig, Idiorm/Paris

I need to work on PHP website recently and were looking for libraries and framework to approach it better with the latest components available. My previous perception on PHP is that it has has a lot to catch up with existing solutions on Ruby and Python. However, this time it seems it already has done it's homework and now has many options regarding some development in web programming e.g: Template Engine, Microframework, ORM.

Here several libraries/framework that I find can form a good combination for small to medium project :

  • Slim is a micro framework for PHP. It is a good enough to help separate the web application into a more modular, decoupled architecture (call it something like MVC if you like). It's a very low-cost approach compare to using full-blown framework like Zend. In Python, I used Flask and it's quite similar.
  • Twig is a templating Engine. It's like Jinja in Python. In fact, the initial coder is Jinja developer, so it's not too strange that it feels quite similar. I don't think people should write/generate HTML code inside PHP directly  anymore. It's inhumane :). Templating engine helps the code deal with the logic exclusively while it deals with how to present it. It has a good two-ray integration with Slim above : there's Slim extension for Twig and Twig can be plug to Slim as Template engine.
  • Idiorm/Paris is a a very light ORM layer for PHP. It just one class and one file with a straightforward and simple uses yet it does the job really well.
So far, I find the combination above serve me quite well. They are quite flexible, does not force too much assumptions/model and has small learning-curve and overhead.


Daniel Ribeiro said...

And how the architecture looked like?

Hafiz said...

Hi Daniel,

There's not much an "architecture" really since the three of them are quite light wieght.

The core of the architecture is Slim. Inside Slim, the data-related tasks are done using Idiorm/Paris and the rendering of the page is done using Twig through the extension.

Basically :
Idiorm/Paris <- Slim -> Twig

Acqueline Albert said...

When it comes to design google in PHP, many individuals will tell that PHP itself is a design engine. But even if PHP began its lifestyle as a design terminology, it did not progress like one in the the past few decades.