NiceDog nano php web framework

1 minute read

Last week I started on a simple web app that only has three pages. After I got the prototype working I wanted to clean up the code and switch over to using a more robust framework. Normally I would use something like CakePHP (PHP MVC framework). But since this web app is so small and didn’t need all the extra power that CakePHP provided I decided the CakePHP is probably overkill. I did a quick google search and found a nano php web framework called NiceDog. Its a single file, very light, framework similar to web.py for python.

After playing around with the source code for a while I found a few bugs with the system. The tutorial also didn’t include a example project to download and try out. So I fixed some of the bugs and created the example code.

nicedog_update

NiceDog nano php web framework example code. 

<?php
/**
* Created by: Steven Smethurst
* Created on: 28 July 2012
*
* A example file for NiceDog php nano web framework found https://github.com/bastos/nicedog
*/
require 'NiceDog.php';
R('')->controller('Test')->action('index')->on('GET');
R('foo')->controller('Test')->action('update')->on('GET');
R('tag/(?P<tag>[-\w]+)')->controller('Test')->action('p_tag')->on('GET');

class Test extends C{

public function index(){
echo 'Hello world';
}
public function foo(){
echo "bar";
}
public function p_tag($tag){
$this->tag = $tag;
echo $this->render('views/index.php');
}
}

// This is the error page.
function r404() {
echo "Error: 404 Page not found";
}

run();
?>

In the end I decided against using this framework as it has obviously not been toughly tested enough for production and the lack of support from the community.

Leave a comment