Lithium, Doctrine & doing it yourself

If you use CakePHP you’ll probably be aware (or you’re dead or on holiday or something…) that Gwoo and Nate have left the project and gone elsewhere. Sort of. Well actually they have forked Cake3 into Lithium – souped up CakePHP for PHP 5.3

Unfortunately I’m not going to be using it in the immediate future due to the 5.3 limitation, but I had a good look through the blog example and it looks like it would be a pleasure to work with.

Looking round the Lithium site I also came across Doctrine – an object relational mapper (ORM) system. I spent an evening reading the documentation and decided it was perfect for a project I’m working on at work, unfortunately the next day I discovered we aren’t up to the required PHP version yet (almost, but not quite) so on the back burner for now.

I’m building a small application (about 8 tables) to be integrated into an existing CMS system. The structure of the CMS is essentially front controller based with a great template engine and well developed plugin / module system. The new module I’ve had to develop just didn’t fit well into the existing code structure and so I have ended up writing a Model / Controller system within my module that utilizes the things like the DB library, routing, security, templating etc. of the parent application.

The setup is pretty straight forward – a base model and base controller extended by respective models and controllers for each table. The child controllers and models are mostly pretty thin – mostly just setting class specific instance variables and the calling methods in the base classes with parent:: There isn’t any fancy ORM or anything like that in the models, just good old fashioned SQL, one query or closely related group of queries per method.

It took me about 1 1/2 days to write the framework and about another half day to write the templates (I’ve still got a load of reporting etc. to write) but now I’ve got the views for all the CRUD operations I will need and a lot of reusable code. Thinking about it, I would probably have done about a quarter of the work, in a far less maintainable way if I hadn’t taken this route. Goes to show that as long as your goals are well defined – this kind of approach far from being overkill has saved a huge amount of time and produced very understandable code – and you don’t need an entire framework to do it (with the added advantage that if you write stuff yourself, you hopefully have a better grasp of what is going on).

(I’ve still written a fair amount of Cake code this week :))

My first bit of Mootools and centering a Google Map in a hidden div

Started a new job last week for a really cool agency in a place I really want to work* – but they are Mootools users not jQuery folk, so I am been thrown headlong into (among other things) the world of Mootools. I’m used to just sitting down and being able to make things work quickly and painlessly with jQuery and it is funny being back to basics again. Today I wrote my first useful bit of Mootools code, which in the grand scheme of things is nothing – just a nice fading toggle to show and hide a Google Map – but it still felt good.

Along the way I had to ran into a problem with my map – when I showed it the centre-ing was gone – I tried all sorts of things… map.checkResize() didn’t work and map.setCenter() didn’t work.

Eventually I deduced that first you actually need to call both functions – reset, then centre e.g.

    map.checkResize();
    map.setCenter(new GLatLng(51.90568, -1.33214));

Along my way I have found a great article comparing jQuery and Mootools – which I would recommend to anyone going either way.

*But it is a kind of a personal philosophy not to ever say on my blog where I do work, just because. I’ve taken over a big project running on a Cloud server written by a load of other people, the sort of thing that is hard but very rewarding.
** I have no idea where those coordinates are. Maybe Up North somewhere?

Ernest Marples postcode lookup is disabled

A while ago I came across a great UK postcode lookup service http://www.ernestmarples.com/ and wrote a post about it here.

Just went back to it a few days ago and unfortunately the service has been suspended. Luckily I didn’t have any applications using it (I mostly use the Google or Yahoo) – but it was a damn fast way to just get the co-ordinates of a UK postcode.

It’s just a shame that such a useful service has been shut down – obviously postcode data is worth a lot of money to Royal Mail – but surely more economic value could be extracted if postcodes were free.

If you are interested in how this pans out there is a blog.