MWF — Masnun's Web Framework

I was a bit fascinated by the URL mapping techniques implemented by Google in GAE. I know most/all of the MVC php frameworks are going to support custom URL mapping. But I was looking for a simple one. And not finding one that is exactly what I wanted, I wrote my own web framework :P

The project is still in beta and currently it can only map incoming requests. You need to build URIs as functions. Analyzing the incoming request, the framework calls the corresponding fuction.

<?php
include “mwf.php”;
$webapp = new MWF();
$url['/regex/'] = “home”;
$webapp->map($url);
?>

<?php function home() {?>
<html>
<head><title><?php echo $_SERVER['REQUEST_URI']; ?></title>
</head>
<body><b>You requested:</b> <?php echo $_SERVER['REQUEST_URI']; ?><br /></body>
</html>
<?php } ?>

In the above code snippets, we see MWF in action. Here, we instantiate the MWF. Map the ‘/regex/’ URI to the “home” function. When a visitor requests the URL http://yoursite.com/regex/, the home() function will be called. In our example the function serves a HTML document. You can also generate other mark ups or simply put some HTTP responses yourself. But remember, the script can not recognize static files. In case of delivering a static file, you have to define it’s URI in the URL map and create a function that serves the file manually. I will give an example of that in a future post.

The MWF class has a default notFound() method which handles any situations where the requested URI is not mapped. You may extend the class and modify this method to define your own 404 page or put some HTTP response.

The URL map still doesn’t support regex. But if I get good response (I am not that convinced that I will get any), I will work on that as well.

The .htaccess file is required and you must have .htaccess support enabled on your host for the framework to operate.

DOWNLOAD LINK: http://php.masnun.com/mwf.zip

Files Included:

  • .htaccess (Apache HTACCESS Conf)
  • mwf.php (Contains the MWF class)
  • index.php (The Sample Application)
This entry was posted in Blog Post and tagged , . Bookmark the permalink.

One Response to MWF — Masnun's Web Framework

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="">