Catching Up on My Reading
Recently I have accumulated a number of bookmarks “to be read later”. Tonight I sat down to read some of them. I revisited CakePHP and I also read a nice article about storing hierarchical data in a database.
I first thought about trees vs RDBMSes when we were designing the Bam CMS. Websites are inherently tree-like in structure. However, a CMS will usually be storing data into a relational database.
The article describes the Modified Preorder Tree Traversal algorithm. The main attraction of this algorithm is that retrieving a node in the tree (a page in the website) requires only one query to the database. Updating the nodes is more expensive, but in a CMS situation, you tend to have many more page requests than page moves/additions/deletions.
I also wandered over to the CakePHP website and read through the new documentation. It seems that a lot has happened since I last looked at the framework. 0.10 Final has been released and the documentation and overall activity has picked up. It is now much easier for a developer to get up to speed with the framework. For those not familiar with CakePHP, here are the goodies:
- MVC Pattern
- Sane file layout
- Pretty URLs
- Easy installation and upgrade of the framework
- Convention over configuration
- Access control lists
- Helpful helpers: html, ajax etc.
- Add your own helpers easily
Like Ruby on Rails, but need PHP? Look into CakePHP. It may be a steep learning curve if you are not familiar with the MVC pattern, but it is worth it. Since the framework, like RoR, favours convention over configuration, it takes a while to get used to the way things are done. Hint: it is easier to go with the flow. Work with the framework, do not fight it. The net gain is consistency and discipline. PHP is a great language, but it is so easy to write crappy code with it if one is not disciplined. A good framework will encourage good habits and highlight best practices.
CakePHP essentially takes the pain out of writing PHP. The framework takes care of sessions, has object relational mapping, makes form building and validation easy, and makes data sanitisation a breeze. The small headaches of day to day PHP fade into the background, leaving you with the more interesting tasks to concentrate on.