Monday, 29 March 2010

Why CakePHP?

A friend of mine, @harryharrold tweeted a very valid question to me the other day:

Out of interest: why not use Drupal? Too heavy? Or did you want to learn more CakePHP? Cos it looks like a view to me? (Doesn't everything?)

This is one of those times where 140 characters is not enough space to do the answer justice, so here's my >140 answer:

  1. Yes, Drupal IS heavy. That said, you get a lot of bang for your buck. Out of the box Drupal doesn't provide all the functionality I'd need for LRPevents.com. At a bare minimum I'd need to install what I consider the Drupal Survival Pack: Views, CCK, PathAuto, an Administrator Theme and a few other must have modules.

    LRPevents has been a back burner project for a long time. I've swapped technologies in and out over the years as I tried out various ideas. At one point I even built a quick Drupal site to see how/if it would hang together. It did, but I never felt fully in control of either the code or the workflow.

    LRPevents.com is not a CMS. It's a front end to a relational database. All the extra code in Drupal for managing a CMS would be wasted and I'd have to write a fair bit of code to get the bits working that Drupal (or its many, many modules) don't provide.

    Drupal is a fantastic piece of work, and version 7 looks to be building into an awesome piece of software. But in this case, it simply wasn't the right tool for the job.
  2. I like CakePHP :-) It's my tool of choice in my real job (we use Drupal too!). I've been using it for a few years now and have gathered together a good toolkit of code and techniques to get things done. Also, I've maned to migrate parts of LRPevents.com into work projects.
  3. CakePHP is easy to expand and incorporate 3rd party plugins. See my other post on getting Twitter Integration up and running in less than 10 minutes.
  4. I like to code! I wouldn't be doing this job if I didn't! A lot of Drupal project work involves setting configuration options, using a gui to build views and tweaking templates. Also, it can be a bit of a bugger to work out what's going on when things go wrong. With Cake you are never too far away from the root of the problem.
  5. The code behind LRPevents.com is relatively simple. Parts are taxing enough to be fun but not difficult enough to have the fun knocked out of it.
  6. Drupal roles and rights aren't flexible enough. The system I have planned for LRPevents.com is very specific and would need me to write custom code in Drupal. I might as well be writing that custom code in a framework I'm more familiar with.
Please note: This is not a Drupal bashing excersise. Drupal is awesome and I'd remcommend it to anyone who needs a feature rich PHP/MySQL CMS. Heck, my blog runs on it and took all of 15 minutes to set up. In the case of my blog Drupal was the right tool for the job.

Sunday, 28 March 2010

Twitter Integration

I've just added Twitter support to LRPevents.com.

Now, every time an item is added to the database, a notification is sent to the LRPevents Twitter account (@LRPevents).

Integration was very straightforward. I dropped Twitter Class into my /app/vendors directory and added the following to AppModel:


function afterSave($created) {

if ($created) {

App::import("Vendor", "twitter");

$twitterUser = Configure::read("Twitter.user");

if ($twitterUser) {

$twitter = new Twitter($twitterUser, Configure::read("Twitter.password"));

$message = "New " . $this->name . ": " . $this->data[$this->name][$this->displayField] . " " . Router::url(array("action"=>"view", $this->id), true); 
$result = $twitter->updateStatus($message);

}

}

}

And put the twitter credentials in /app/config/bootstrap.php:

Configure:write("Twitter.user", "{your twitter username}");
Configure:write("Twitter.password", "{your twitter password}");

Easy eh?

Note: After going live with this feature I found that Twitter Class uses a setting that isn't allowed when your site is running in safe mode. The fix was easy: Just comment out the line


$options[CURLOPT_FOLLOWLOCATION] = true;

in twitter.php


LRPevents Beta Goes Live!

I've started this dedicated blog (my personal blog is Richard@Home) to document the process of creating a new website and to highlight some of the ideas and techniques I've used.

The idea for a site like LRPevents.com has been bubbling away in the back of my head for over ten years! So this weekend, I finally took the plunge, grabbed a domain and hosting at one.com (an excellent, cheap hosting service btw. I wholeheartedly recommend them!) and uploaded the first code to make it all happen.

I'm following the Agile Development practice of release early, release often which ideal for a project like LRPevents.com. It means:

  1. You get a working site up quickly and start to get the valuable feedback from your users
  2. You can incrementally implement new features and fix bugs without a long delay.
  3. You can react quickly to new feature requests from your users.
The website is a CakePHP / jQuery application with a MySQL backend. Everything has been produced using open source tools and technologies. This isn't for any moral reasons, it's the simple fact they are the best tools available.


Currently the site is live with a tiny subset of what I have planned for it but there's enough there already for it to be useful. I've outlined a few of the ideas I have planned in a beta announcement news item on LRPevents.com so I wont repeat them here.

Ideally, I'd love for the site to take off and to generate enough money to cover its costs (and buy me a beer or two), but for now I'm just happy to finally see it up and running :-)

(note: Right now, the site is down. Having spoken to the nice people at one.com it seems PHP is broken but they are fixing it...)