You're viewing a single post. I have much more to say! The main blog page is a good starting point.
Monday, August 8, 2005 ★ 23:11 ★ Category Programming
As a semi-professional web hacker I’ve developed my own set of libraries to be used to create web sites and web applications. Part of this code is written in my spare time, part of it is written while getting paid by my boss. After a quick discussion we’ve decided to license the set of libraries under the LGPL, which means they can be used by anyone willing to respect the license.
Most of you will now probably think ‘oh no not yet another web framework’. Well, my code is not a framework, it’s a set of libraries. As we all know, web frameworks suck and I fully agree on that. Some of you may wonder what exactly the difference is between frameworks and libraries. Well, frameworks force you into a way of coding which you may not find comfortable, whereas libraries grant you total freedom for your own code, while offering an API to use the library functions. So, with libraries you can write your software the way you want, be it hackish or completely clean. Of course, we all prefer the clean way…
My toolkit is named Anewt, which stands voor Almost No Effort Web Toolkit. I’m busy getting the code into a releasable state (minor code cleanup, some extra testing, patching away all TODO and FIXME comments) so there’s nothing to play with yet. Until that time you’ll have to do with two code snippets that demonstrate the power and ease of use Anewt has to offer.
Example 1. My main blog page
<?php
// This file includes anewt code, connects to the database,
// sets up some defaults or does other things you need.
require_once ‘default.inc.php’;
// my blog classes
require_once ‘uwstopia/blog.lib.php’;
$p = new UwstopiaPage($db); // This page implements my design
$p->set(‘title’, ‘Blog’);
// show posts
$posts = Blog::recent_posts(
null, // all categories
null, // default number of posts
$db); // a database object instance
foreach ($posts as $b) {
$p->append_to(‘body’, $b->to_xhtml());
}
$p->flush();
?>
Example 2. Validating database layer
<?php
$prepared_query = $db->prepare('
SELECT
`name`,
`description`
FROM
`article`
WHERE
`id` = ?int?
');
$result_set = $prepared_query->execute(5);
$row = $result_set->fetch();
print_r($row);
?>
The database layer API is really simple. You have to specify the type of each variable you want to use in the query and it won’t run if you pass the wrong type. No more SQL injection problems, no more addslashes() and strip_slashes() horror, yay for clean database use!
Want to see Anewt in action? You are already looking at a site running Anewt! uwstopia.nl is 100% written using Anewt.
I won’t give you any other deployments because I don’t know if my company’s customers would appreciate it. All I can say is that Anewt runs smoothly in at least 5 production environments.
Random photo from Various pictures (June, 2005)
Wouter Bolsterlee, also known as uws, a postmodern geek living in the Netherlands. Read more about me…
Unless stated otherwise, all material on this site is available under a Creative Commons Share-Alike license.