GluePHP — A Spartan URL Routing Framework

For larger PHP projects, it’s a good idea to use the Model-View-Controller pattern and URL routing to organize things a bit more logically and make the code easier to update in the future. Frameworks like CodeIgniter, Kohana and CakePHP do this, but they can be overkill for some projects.

Enter GluePHP.

GluePHP is a lightweight framework (really, it’s a single class!) that only does one thing: it routes URLs to PHP  classes. It “glues” (the developer’s pun, not mine) everything together by routing URLs like example.org/asdf to your class with the name “asdf.” By implementing GET() and POST() methods, you can fire off other methods and output results.

A simple example, that doesn’t use any of the more advanced features like regular expressions in URLs, would look like this (from the documentation):

require_once('glue.php');

$urls = array(
'/' => 'index'
);

class index {
function GET() {
echo "Hello, World!";
}
}

glue::stick($urls);

I would say it’s worth bookmarking if you do much PHP work. It would be great for throwing together quick websites or tech demos.

  • http://kevinlloyd.net Kevin

    I just wish it had functionality for a catch all route.