Web Development

Articles about software development for the web.

Foiled by CakePHP

Yesterday, I was all poised to launch myself over the top and be completely caught up on my Holidailies posting. That was the plan. Unfortunately, something intervened: CakePHP.

As I noted the day before, I built the new Holidailies 2008 site using the CakePHP framework.

One reason I wanted a framework was so that I had a solid structure on which to build new capabilities. As the month of Holidailies has progressed, that's what's happened. One unfortunate side effect, however, is that the complexity of the site has now grown to the point where changes may have an unpredictable result.

CakePHP: The Good, The Bad, and The Hurty

As I noted in a previous article, I opted to use the CakePHP framework for the Holidailies 2008 rewrite. It's a PHP framework for web application development. It implements the MVC (model-view-controller) design pattern commonly found in web frameworks (such as Ruby on Rails). I made a very good choice moving Holidailies from complete custom code to a framework. I'm not completely happy, however, with my choice of framework. I'll tell you about some of the things I've found.

What I Liked

The best thing is that it implements magic ORM (object-relational mapping). Manual ORM, such as that implemented by Hibernate, is a major annoyance. You have to create all these useless getter/setter classes, construct an XML index, and go through a lot of work to build the ORM. And heaven help you if you make any schema changes. It's painstaking and fragile.

Rate Link Patch

I mentioned last week that I added a "rate this post" feature to my blog using the Drupal fivestar module.

There is a serious usability issue with this module. If you don't show the rating widget on the article teaser then visitors probably won't know there is a rating feature, and so there may not be a lot of rating activity. (The teaser is the first few paragraphs of the entry, displayed on the blog page.)

Comments work similarly to ratings. You have to click through to the full article to leave a comment, just as you do a rating. This, however, doesn't present the same problem as article ratings. First, visitors tend to know that if a blog supports comments, you have to click through to the full article to access the comments. Article ratings aren't a common feature, so visitors don't expect them.

Sidebar Block Plugin for Smarty Templates

HTML templates allow presentation to be abstracted from control. Abstraction, like water, is good—but be careful or you'll drown.

Take sidebar blocks. HTML templates make it easy to abstract the sidebar, but what about the individual blocks?

You could make each block its own template, but you end up juggling so many miniscule pieces you lose track of all the bits. Do you really need a dedicated template just to put an RSS icon in a box?

On the other hand, if you eschew templates and code the blocks all up in the sidebar, you get a large unstructured mess of HTML.

What we need to do here is abstract the structure, not all the little bits of content.

The Smarty template system for PHP has a good solution. You can use the plugin mechanism to create a custom template tag such as {block}. That makes it easy to place blocks in a sidebar template in a structured fashion. I did this for the Holidailies web site.

Here is how a sidebar block looks on Holidailies:

a sample sidebar block from the Holidailies web site

Syndicate content