Nested menu with PHP’s RecursiveIteratorIterator

The Standard PHP Library (SPL) has been around for years now, yet we don’t see them being used in our daily codes. Frameworks like Symfony2, Laravel use them internally. Today I am writing about one of the key members of the SPL, the RecursiveIteratorIterator, and implement something web developers always have to deal with, nested menus.

As the name suggests, it is used to iterate through a recursive iterator. There are many recursive iterators provided in SPL like RecursiveArrayIterator and RecursiveDirectoryIterator. A recursive iterator should implement the RecursiveIterator interface. There is not much documentation about these in the PHP website, but there are examples you can learn from.

If you have never used any of the Iterators, you can think of them as ‘loopables’.  The `RecursiveIterator` interface extends `Iterator` which extends `Traversable`, which is described as “Interface to detect if a class is traversable using foreach“, meaning iterators can be directly passed to foreach and looped. Continue reading Nested menu with PHP’s RecursiveIteratorIterator

Deploying symfony2 project with capifony at hostgator shared hosting(subdomain)

I was recently working on a Symfony project and I needed to deploy it to a shared hosting at Hostgator. The default PHP version in Hostgator shared hosting is 5.2.17 (thats in mine). Some of you might know that Hostgator provides support for other versions of PHP as well (5.3 and 5.4). I use Capifony to deploy my symfony projects. So I had to made some adjustments to the deploy recipe that helped me successfully deploy a symfony2 (2.3.7) to a shared hosting in Hostgator. And I put here the full procedure to successfully setup capifony for deploy at Hostgator. (This was a staging deploy to a subdomain. If you need to deploy to your primary domain, I’m afraid Hostgator does not allow you to change the DocumentRoot for your primary domain. See this link to know more on changing DocumentRoot at Hostgator) Continue reading Deploying symfony2 project with capifony at hostgator shared hosting(subdomain)