I Made a Cake With PHP Goodness

October 20th, 2007 by ScottK | No Comments | Filed in Programming

I like to think of myself as a horizontal programmer that looks at different languages rather than a vertical programmer which specializes in one language. In terms of the Model-View-Controller architecture I’ve programmed in C# and now Ruby on Rails. I knew however that there was other languages that could support this architecture and I wanted to try them out.

As far as Ruby on Rails goes there is a ninche market for web hosting for rails apps. Because of that I don’t feel right about being limited to my hosting choices if I ever get upset with the provider. I did try to set up my home box with mongrels and completely messed it up. So to me it’s the hosting requirements that make a Rails app un-popular to me.

I’ve also looked at Django and that is a sweet framework. I’ve recently taken a likeing to Python and Django makes use of it to deliver the framework. One of the excellent points is that an administration page can automagically be created as well so application development is even faster. Since one Django project can hold many applications the admin section has access to all of these. I run many sites that have admin sections and this would be a great feature.

However Django being written in Python requires the mod_python module in Apache and an entry in the virtual host file. On my home box that is not a problem. On a hosting provider though it may be a problem. In part they provider may not have mod_python installed nor would they want to alter the conf file.

Another issue I found with Django is that it is still young and going through active development. The current stable version being .96 works but the development version .97 has made some core changes so depreciation warning are going to happen. Also clearly stated serialization is under heavy development and changes are being made to the authorization modules. So as sexy as it is I think I’ll wait a few versions.

I just spent all of today playing with CakePHP. CakePHP is a MVC framework written in PHP so naturally I must admit I am biased when I say I’m going to love it. Along with the framework you are given tools to generate new models, views, and controllers from the command line and choice are included for scaffolding and tests as well. That’s known as cake bake. :)

Before I explain my experience let me say I am using the development version 1.2.0x alpha version and not the 1.1.17.x stable version. Although I did have to down grade to test something and discovered that there are differences between the two in the behind the scenes code. Plus several key functions are going to become depreciated in favor of better organization. I’m sticking with the development version and if you’re wanting to try cakePHP then go with that also.

For starters the documentation leaves a lot to be desired. The API manuals are just fine so that’s a bonus but it’s the other documentation such as setting up the routes that hurt. The tutorial does explain this with a Post example but it would have really been helpful to see a routes file set up for a Post controller and a News controller. Now granted it only took me two hours to figure out and fix the problem on my end as to why mod_rewrite was not working. Once I got that done the routing took over nicely.

After a few learning experiences I finally got a default layout up and running with a few test different routes for testing. Everything went well and as expected until I decided to start including javascript. Even though it’s offered as a helper the JavascriptHelper is not available to views without being included in a controller. HtmlHelper and FormHelper are available but those do not allow me to do the script include in the head section. That’s bad in my opinion. Nor is there a generic helper application file. Something I could just pop in a quick helper and it’s globally available, something like the script includes I just mentioned.

It may seem that I am displeased with cakePHP and that is not the case. I am totally looking forward to working with it. Once of my concerns was the file structure. Although the tutorial suggests to point the host directory in the apache config file to the cake webroot you do not need to do this. just upload the whole kit and kaboodle to the web root folder and it will work. That means any hosting provider that supports PHP and allows you to modify your htaccess will work with cakePHP. In less than twleve hours I took cakePHP with no knowledge and had a working application. Even made my first helper for the head meta tag stuff.

Whether it is or isn’t Ruby on Rails is just to difficult to manage and hosting options are limited. Django is just a bit to young at the moment but when it matures it’s an awesome framework. cakePHP is both stable and active with a huge base of potential contributors from the PHP community. For now call me a baker of cake.


Share Your Thoughts