MWF Reborn

I have been enough bored when I finally decided to rewrite the MWF from the scratch. I wrote this webapp framework and named “Masnun’s Webapp Framework” weeks ago. Gradually I forgot about it like many of my other projects I didn’t get the time to complete. But I needed a webapp framework pretty badly for the ongoing free lance projects at hand. The buyers hire me for doing the programming part and create the HTML templates by other professional designers. Then I have to merge my program into the HTML. It’s a pain if I don’t use some sort of templating engine. Again, I want the URLs to look professional and structured. To meet these needs, I had to go for a web application framework. I liked the web.py framework for Python but most of my clients want me to use PHP. I have tried CodeIgniter and Smarty. But they are huge in overhead and feature packed. I don’t really need half the features they provide.

Keeping all these in head, I started re-writing the MWF from scratch. This time I have managed to build a fully functional URL router that is smart enough to support regular expression. I have also managed to create a templating system for it. Though it’s nothing cool if you compare to the popular frameworks, it does serve my purpose.

I have included a MIT license in this release and uploaded it to my google code repository for downloads.

Download: http://masnun.googlecode.com/files/mwf.zip :)

How to use it?
Using it is quite simple. You’ll find a demo inside the downloaded package.

It doesn’t have any models. Just URL routing and templating for now.

– First include the library.
– Map the URLs to callback functions. These URLs are matched using regex and if matches the path is sent to the callback function as the only parameter. We define the URL routes as comma separated pairs. I could use a dictionary but I liked this way. I have found it fun while exploring web.py. First the URL pattern, then the callback function for it, then another pattern and it’s call back function, another pair in this way and it goes on… :)

– Start the web app.

– Define the callback functions.

Sample

<?php
 
include('mwf.php'); // include the library
 
// route the urls. first the url, then the callback function name
// url pattern supports regex
// matched url will be sent to the  callback function as the only parameter
 
$urls = array("/masnun","redir","/tag/[\w]+","home");
 
// done. run the webapp
mwf_run($urls);
 
// Define the callback functions which work as controllers
 
function home($path) {
/*
 
To render a template, feed the function with a php file
and an associative array of key-value pairs (dictionary)
 
 */
template_render('views/layout.php',$dic = array("tag" => $path));
}
 
 
function redir($path) {
// Use the mwf_redirect() function for url redirection
mwf_redirect("/tag/home");
}
 
?>

That’s it… Quite simple… ;-)

Tags: , . Bookmark the permalink.

One Response to MWF Reborn

  1. hasin hayder says:

    great. keep up the good work.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">