The Idea Basket
“When you find yourself wanting to jump on a design trend, ask this simple question: does this really work for me? Sometimes a trend is just a style that appeals to small number of people.”
— Jared White

November 2006

Some time off for Willowgarden

November 7th, 2006

As you may have ascertained, I’ve not had much time to work on Willowgarden for quite some time. I have to admit I was disappointed in the lack of interest in the Developer Preview 2 release from a community perspective. Perhaps it was partially my fault, since I never got a chance to flesh out the end-user documentation to the degree I wanted, and many an open source project has been stymied through a lack of simple, clear documentation.

However, I’ve been really happy with DP2 as a platform for my own Web apps and sites, and so I really can’t complain about any of the work I’ve put into it. One such project is the Native American Flute Portal which just launched today — yay! With a few exceptions, the entire site was built on top of Willowgarden, and I’m extremely pleased with how well it’s worked out.

Another PHP project that’s shifted my attention away from Willowgarden is xajax, which of course is used by Willowgarden for the Ajax layer. xajax is in the process of a huge rewrite leading up to a 0.5 release, and I’m happy to say we’ve had some pretty neat action there due to the addition of a new developer (”CtC” aka Joseph Woolley). Much fun on that front is yet to come.

So, to wrap this post up, Willowgarden has met my personal expectations from a technology standpoint, but as a viable open source project, it just isn’t there. So I’m going to maintain a pretty low profile for a while and put off another big marketing/release push (aka 1.0 Beta 1 or something like that) for some time. I’ll be checking in tweaks and minor improvements here and there in the Subversion repository, but that’s about it. As always, I’ll keep you folks posted here at The Idea Basket!

September 2006

Willowgarden Highlight: Easy Processing of Form Input

September 19th, 2006

Welcome to this week's installment of Willowgarden Highlights. I'll be talking about processing form input and saving it via an archetype (domain model object), a very common task of any Web application.

In the bad old days of processing forms and saving each field to a column in a database row, you'd have to do a lot of manual gruntwork: accessing each field from the $_POST superglobal, checking the values, constructing the SQL query, connecting to the database and executing the query, and so forth. Wouldn't it be great if you could just import the form right into an object, and let it do the validation and the database saving based on just a few simple rules? Let's take a quick look at how that might work.

The easiest way to create a form ready for import is to use the WFFormCreator class that comes with Willowgarden. Here's an example of a form for entering a project task:

PHP:
  1. <?php
  2. $form = new WFFormCreator();
  3. echo $form->startForm("name: taskForm", "URL:", WFMakeURL('create', 'action'));
  4. $form->useNamePrefix("ProjectTask"); // this is important
  5. ?>
  6. <table>
  7. <tr>
  8. <td>Name of the Task:</td> <td><?php echo $form->newTextfield("name: name", "size: 30") ?></td>
  9. </tr>
  10. <tr>
  11. <td>Comments:</td> <td><?php echo $form->newTextarea("name: comments", "rows: 10", "cols: 60") ?></td>
  12. </tr>
  13. </table>
  14. <div><?php echo $form->newSubmit("title: Add This Task") ?></div>
  15. <?php
  16. echo $form->endForm();
  17. ?>

So what we're doing here is creating a form that will call the "create" action of the current page when the form is submitted. In the form, we output a textfield for the task name and a textarea for comments. But notice that line of code near the top that calls the useNamePrefix method of the form object? That sets up the form to use that prefix in the field name for each form element. So the actual name of the comments field isn't "comments" but is in fact "ProjectTask.comments". (Periods get translated to underscores in PHP, so in PHP you'd get "ProjectTask_comments" in your $_POST superglobal.) And of course, the name of the "name" field is in fact "ProjectTask.name".

Now in your page controller, you can write some very simple code to process the incoming form. Here's an example:

PHP:
  1. public function create_action()
  2. {
  3.    $task = new ProjectTask();
  4.    $task->importFromArray($_POST);
  5.    if (!$task->isValid()) {
  6.       $this->getRenderer()->assign("validationErrors", $task->getValidationErrors())
  7.        ->assign("task", $task)
  8.        ->render("add");
  9.    }
  10.    else {
  11.       $task->save();
  12.       WFRegistry::getRequest()->redirect("view/{$task->id}", "action");
  13.    }
  14. }

You can start to see where we're going with this. In the "create" action, we're instantiating a new ProjectTask object (a subclass of WFArchetype). Then we're importing data from the $_POST superglobal (which is by default filtered by the input filter that comes with Willowgarden to prevent Javascript and CSS hacks). The archetype is smart enough to check for the prefix of each form field to see if matches its own class name and import only those values. Then we're checking to see if the archetype is valid (i.e., all the form fields now stored in the archetype validate according to the archetype's validation rules) -- if it isn't, we'll obtain the validation errors and render the add form again; if it is, we'll save the archetype and redirect the browser to the view action with the new task's "id" as a path parameter.

Showing how to set up the ProjectTask archetype with database access and validation rules is beyond the scope of this article, but I hope now have a sense for how Willowgarden's Logic and Render layers (Controller and View layers in MVC parlance) work together very well to make your job as a Web developer much easier. One of the great things about the name prefix feature is that you can use multiple prefixes in the same form, allowing you to import the exact same form array into multiple archetype classes without causing any conflicts. You can also use prefixes for the id of form elements, which is a feature I'm using a lot in one of my applications.

And that's it for today's Willowgarden Highlight! Come back soon to learn more about this exciting new application platform for PHP 5.

Willowgarden Highlight: Template Modes

September 12th, 2006

Welcome to the first post in a series of posts I'll be writing about highlights of the Willowgarden application platform for PHP 5. This first highlight may be a simple one, but it's a very useful one as you will shortly find out.

Willowgarden, like many Web frameworks, is built around the concept of pages and actions. A page such as "photo" might have actions such as "view", "edit", "remove", etc. Some actions are visual and don't alter content, and some actions do alter content and aren't visual (they redirect to a visual action). The visual actions, of course, need to output HTML to the browser. How does that work? Well, as you might think, every page has a template associated with it, which you use via the page's built-in renderer to render the template. But, unlike many Web frameworks, Willowgarden doesn't provide a different template for every action. All actions are provided via a single template file for the entire page. This works because of the concept of template modes. (Note: for the purposes of this article, we're assuming we're using the default PHP-based template engine.)

Say someone wants to edit information for a photo. They'll go to a URL such as http://www.mysite.com/photos/edit/12345, which means the edit action of the photos page will be called and the first path parameter will be 12345. Now obviously you only want the HTML for the edit action to be rendered; you don't want the HTML for the view action or the process action or whatever to be rendered. So in the template file ("photo.php.tpl"), you would do this:

PHP:
  1. <?php
  2. if ($this->getMode() == "view"):
  3. ?>
  4. <p>Hello. This is the view action template.</p>
  5. <?php
  6. endif;
  7. if ($this->getMode() == "edit"):
  8. ?>
  9. <p>Hello. This is the edit action template.</p>
  10. <?php
  11. endif;
  12. // and so on and so forth
  13. ?>

Not bad, eh? Of course, the tradeoff of more files that are simple vs. fewer files that are slightly more complex might seem like a draw. But, and this is a big but, this template isn't in and of itself action-specific. So you can do tricks like this:

PHP:
  1. <?php
  2. if ($this->getMode() == "add" || $this->getMode() == "edit"):
  3. ?>
  4. Welcome to the <?php echo ucwords($this->getMode()) ?> area.
  5. <?php
  6. endif;
  7. ?>

Aha! Now we're handling two different template modes in one pass. We can have specific bits of the template for either action output different HTML based on the mode but keep much of the HTML the same. This is very helpful when we deal with "add" vs. "edit" -- 90% of the page content might be the same in either case. With sophisticated use of template modes, you can keep 90% of that HTML in one single place. Bottom line: managing your HTML templates just got a whole lot easier.

I hope you enjoyed my first Willowgarden Highlight. Come back soon for #2!

Developer Preview 2 of Willowgarden has been released today

September 8th, 2006

Willowgarden is an application platform/framework for PHP 5 that I started work on towards the end of August 2005, with serious development progress starting around the beginning of the year. On April 28, I released Developer Preview 1 of Willowgarden, and while that was a good start, I knew that the project still had a long way to go before it would resemble the level of quality and scope of functionality that it really deserved.

Well today, I'm so pleased to announce that Developer Preview 2 is ready. This is where the project is really starting to solidify and settle into a cohesive whole that can be used for hands-on development. I've been working on several Web site and applications using the DP2 codebase, and it has made my life as a PHP developer so much more fun than the bad old days of cobbling together scripts nearly from scratch.

Along with DP2, I've set up a new wiki that houses the partially-complete Users Guide as well as areas for future tutorials, how to's, and more. I'll be spending a lot of my time in the near future working on that end of things rather than code. You are most certainly welcome to contribute content to the wiki as well, so be sure to check that out.

And now I am going to make a bold statement: I am asking the cutting-edge PHP 5 developers reading this -- and I know you're out there! -- to consider joining the Willowgarden project if it piques your interest. I would like to start moving interim versions out there at a more rapid pace, leading towards a stable 1.0 release of Willowgarden, and to do that I need the help of people with many different environments and expertise in fine tuning installations. I also have a huge number of ideas in store for future versions, and I'm sure you do as well. This is the time to get on board while the project is still young! To contact me, feel free to send me an e-mail (remove everything after jared before the @ sign).

Thanks for reading, and I hope you download Willowgarden DP2 and give it a thorough look-over. This release is stable enough that I encourage you to start using it for your experimental development efforts, and your feedback and ideas are very much appreciated. Also, I'll be posting a lot here now about DP2, so check back soon for more information as well.

Willowgarden DP2 coming today!

September 8th, 2006

Hi folks -- just a quick note to let you know I'm on track to release Developer Preview 2 of the Willowgarden application platform for PHP 5 later today. Check back soon!

Just a tiny delay

September 4th, 2006

Silly me! I forgot today, Monday, is Labor Day here in the U.S. I also got a couple of projects that came up at work suddenly, so I've decided to push back the release of
Willowgarden DP2 'till the end of this week. Thanks for your patience! It'll be worth it. :)

August 2006

Cross your fingers! September 5 = DP2

August 30th, 2006

Willowgarden is a PHP 5 application platform that enables you to build fantastic Web applications. The Developer Preview 1 release, which came out in April, was really just a sneak peak of what was to come. Now we're almost ready for the Developer Preview 2 release, which is a much more robust, full-featured, exciting platform that will build far more awareness of the project (and having a true Subversion repository available for open source access is also a big help).

I've picked September 5 as the launch date for DP2. I'm working hard to make this a reality, so definitely mark your calendars and come back here next Tuesday to experience the next generation of Willowgarden. I'm sure looking forward to it!

Back in the Running

August 21st, 2006

Hey folks, I'm back! After being gone for a few weeks due to a family emergency, I'm now ready and rarin' to go. First on the agenda: getting Willowgarden Developer Preview 2 out the door! The first step in that direction is adding the code to a Subversion repository, and to that end I've put Willowgarden up as a project at Sourceforge.net.

So, the good news: the codebase for DP2 is now available via SVN and is roughly 95% complete! Yay! The bad news is that it'll be probably another week at least before I've worked enough on documentation, sample code, tutorials, etc. to feel comfortable building an official DP2 release. But if you like to be on the bleeding edge of tech, by all means go ahead with the SVN code. Please note: you'll need to read this post at the Willowgarden forums in order to set your environment up correctly.

In other news, xajax 0.5 is still on the table, and I'm hoping we can get a beta release out by late September. Keep your fingers crossed! Much more news on that to come in the days ahead.

Thanks for your patience, and I'll see you again here very soon!

Willowgarden DP2…preview of a preview?

August 2nd, 2006

I've changed my mind. See? That's what having an open mind will do for you! :) No, seriously, I have changed my mind, and what I'm referring to is the release plans for DP2.

I now realize I was too ambitious. I tried to "pull a Vista" (sorry Microsoft) and come out with a new release with practically everything new, improved, re-engineered, etc. Like Vista, it has resulted in a long delay and a lapse of immediate functionality improvements for interested users. Unlike Vista, I'm actually getting close to done with what I wanted to accomplish, and I'm pretty happy with the result.

So, as I said, my plans have changed. What I'm working on right now is cleaning up my current codebase enough to release something of use on Sourceforge right away. I hope to have a working Subversion repository up by early next week containing what will soon be known as the official DP2 release. Most of what needs to be accomplished before DP2 is formally unveiled is related to documentation, Web site changes, tutorial code, etc., so I figure in the meantime the real core code should be made available to the public for the cutting-edge developers out there to poke at.

Like I said, by early next week, you should be able to check out a real working copy of the DP2 codebase. If you're just a PHP developer dude or gal who wants to slap a Web site together with a framework in a couple of weeks, don't touch this with a ten-foot pole. But if you're an advanced PHP whiz who wants to discover the latest and greatest and help to make it even better, give it a try!

July 2006

Episode 1 of my new video blog

July 20th, 2006

Hey everyone! I've started a new video blog to be an adjunct to The Idea Basket, so sometimes when I feel like doing something more fun than typing on a keyboard, I'll post a new video episode instead. You can watch the video on the jump, or visit this page at YouTube. This short introduction just gives you a basic run-down of the upcoming upgrades to xajax and Willowgarden.
Read the rest of this entry »