Glue is a web framework for quickly creating web applications in PHP with minimal effort inspired by sinatra
Latest commit 2a13a56 Dec 30, 2010 @faulancer faulancer readme added
Failed to load latest commit information.
vendor/glue readme added Dec 30, 2010
.htaccess initial commit Dec 26, 2010
index.php hello world example fixed Dec 29, 2010
readme.markdown readme added Dec 30, 2010


Getting Started

Glue is a web framework for quickly creating web applications in PHP with minimal effort inspired by sinatra:



glue("route")->get("/", function(){
    echo "Hello world!";



In Glue, a route is an HTTP method paired with an URL matching pattern:


glue("route")->get("/", function(){
    // .. show something ..

glue("route")->post("/", function(){
    // .. create something ..

glue("route")->put("/", function(){
    // .. update something ..

glue("route")->delete("/", function(){
    // .. annihilate something ..

glue("route")->get("404", function(){

    echo "Uuups, route not found!";

Routes are matched in the order they are defined. The first route that matches the request is invoked. Route patterns may include named parameters, accessible via the params array:


glue("route")->get("/hello/:name", function($params){
    // matches "GET /hello/foo" and "GET /hello/bar"
    // $params["name"] is 'foo' or 'bar'

Route patterns may also include splat (or wildcard) parameters, accessible via the $params[:splat] array.


glue("route")->get("/say/*/to/*", function($params){
    // matches /say/hello/to/world
    // $params[":splat"] => array('hello', 'world')

Route matching with Regular Expressions:


glue("route")->get("#/hello/([\w]+)#", function($params){
    // matches /hello/mia
    // $params[":captures"] => array('mia')


Routes may include a variety of matching conditions:


glue("route")->get("/ie", function($params){

    echo "Only for the IE's ....";

}, strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'));


In general you can utilize any template engine you want. Glue provides a simple template engine:


glue("route")->get("/", function(){

        $data = array(
            "name"  => 'Frank', 
            "title" => 'Template demo'

        echo glue("template")->render("views/view.php with views/layout.php", $data);


    Hello <?php echo $name;?>.


<html lang="en-US">
    <meta charset="UTF-8">
    <title><?php echo $title;?></title>
    <?php echo $content_for_layout;?>

Database access? Sure!

A simple database helper provides you access to mysql (more to come).


glue("pdo")->addSource("default", array(
      'dns'       => 'mysql:host=localhost;dbname=test',
      'user'      => 'root',
      'password'  => '',
      'options'   => array()

glue("route")->get("/items/ids", function($params){

    //get an array of all ids
    $ids = glue("pdo")->src("default")->find(array(
        'table' => 'test'
        'fields' => 'id'


You like OO style? Extend GlueBase!

Define your routes in the comment for your method.



class App extends GlueBase {

        @Get /
    public function index() {
        echo "Hello world!";

        @Get /test/:name
    public function test($params) {
        echo $params['name'];