Archive

Archive for February, 2008

Frameworks

February 26, 2008 1 comment

Over the years I’ve written a number of web applications basically from scratch.  I almost always use PEAR and other libraries, but for the most part I’ve always used my own code as the basic framework.  Last year I started building a number of modules for Drupal, including some that automate business processes (such as inventory and producing PDF documents for brochures based on live business data).  This is convenient because these modules fit nicely into  larger intranet type sites for the organizations that use them.  But Drupal isn’t really designed to be an application framework.  Since it isn’t intended to be that, they apparently feel free to completely redesign key parts of the API between versions, which really makes upgrading expensive.

So more recently I’ve been looking again at a couple of  the frameworks that are available for PHP, this time Solar and Zend Framework.  I’ve looked at these before, along with Cake.  I didn’t care for Cake, and ZF and Solar weren’t ready yet last time I looked.

Solar and ZF are much closer to ready for real use now than they were last time I looked closely at them.  Over the weekend I built a few simple prototype level things from both Solar and ZF.  The short of it is that I really like Solar.  It is very easy, and I found it very intuitive.  I shouldn’t be surprised, Paul M Jones has a history of writing good stuff.  I had a site running in very short order with Solar.

I think that the main problem with Solar is the size of the community.  I need a number of the features that Zend Framework provides, but aren’t available for Solar yet, like SOAP, XMLRPC, RSS, support for MS SQL server connections (I’d rather not need that, but I do), and others.  I could write them for Solar, but most of what I need is already available from ZF.

Zend Framework doesn’t have the conceptual consistency and elegance of Solar, and I’m having a hard time piecing together the bits of it that I need.  Its sort of like building your own Linux from scratch, maybe something every Linux geek should do at least a couple of times but not something you want to do when all you need is a working computer to get stuff done.  When you just need to get work done you want a Ubuntu or OpenSuse to package it for you so you can just get to work.

In the end, ZF is more like PEAR on steroids than it is the framework I want to save me time in piecing something together.  Still, I think its the closest to what I need, and it has the momentum and support behind it to have a rosier future.  So I guess the best approach would be to build my own blank application from the pieces I will commonly use, with all of the components I commonly will need bundled in already, and archive that as an application template.

Or maybe I’ll try Solar some more.

Or maybe I’ll just keep cooking my own.

Advertisement
Categories: PHP

Test first or test later

February 20, 2008 Leave a comment

A lot has been said about test driven development.  While I am a proponent of testing, I am not a fan of test driven development.  I could go on at length about it, but actually somebody else has already said it clearly, so here’s a link to what Paul M Jones said about it instead of boring everybody with a retelling here.  I’m pretty sure he’s smarter than I am anyway.

Categories: development

Prettify code blocks

February 20, 2008 Leave a comment

Google has a project to do “syntax highlighting of code snippets in a web page” using javascript.  Its here:
http://code.google.com/p/google-code-prettify/

Categories: note to me

Safely mashed

February 20, 2008 Leave a comment

I’m working on a mashable page for FH’s intranet, and one of the potential issues is safety if we allow content that isn’t on some “approved list”. That’s exactly the point of Caja (from Google) – “A source-to-source translator for securing Javascript-based web content.”

The Caja page also links to some other pages of groups working on other problems. Most notably:
The Caplet Group (on Yahoo tech groups) : The Caplet Group is discussing the situation of the web browser, in particular the Mashup Problem, and the possibility of using a capability messaging system to allow safe and useful communication between frames, worker pools, and other client technologies.

Categories: note to me

Dynamically add fields to forms

February 15, 2008 Leave a comment

On my old site I had an example of adding fields to forms dynamically, which continued to get hits even long after I had forgotten it was there. The example looked like this:

City
Address1
ZIP
Phone Number
Name

The code looked like this:

[cc lines=”20″ lang=”html”]

function forminsertrow(theForm) {
var insertHere = document.getElementById(\’cloneme\’);
var newElement = document.getElementById(\’cloneme\’).cloneNode(true);
insertHere.parentNode.insertBefore(newElement, insertHere);
}

Search For:

City
Address1
ZIP
Phone Number
Name

[/cc]

This leaves you with kind of an ugly array that looks something like this:
[cc lang=”php”]
$_REQUEST[‘search’][0][‘field’] = ‘address:city’;
$_REQUEST[‘search’][0][‘value’] = ‘Phoenix’;
$_REQUEST[‘search’][1][‘field’] = ‘name:full’;
$_REQUEST[‘search’][1][‘value’] = ‘David’;
[/cc]
You generally need to do something with this to make it more usable. A loop like this one transforms it into a more nicely formatted array:

[cc lang=’php’]
foreach($_REQUEST[‘search’] as $key => $value){
$search[$value[‘field’]] = $value[‘value’];
}
[/cc]
I have used this approach quite successfully, and visitors seem to find it easy to work with. If I was doing this now, I would probably use a javascript library to do the clone part. For example, with jQuery, you don’t need the function at all. Just change the onclick on the button to this:
[cc lang=’javascript’]onclick=’$(“#cloneme”).clone().appendTo(“#cloneme”);'[/cc]
In fact, that’s what the working example above actually does.

Categories: javascript