O'Reilly logo

CouchDB and PHP Web Development Beginner's Guide by Tim Juravich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — adding simple but powerful helpers to Bones

Let's add two little functions to our lib/bones.php file that will help us use forms.

  1. Add a function called form that looks as follows:
    public function form($key) {
    return $_POST[$key];
    }
    
  2. Add a function called make_route. This function will allow our Bones instance to create clean links so that we can link to other resources in our application:
    public function make_route($path = '') {
    $url = explode("/", $_SERVER['PHP_SELF']);
    if ($url[1] == "index.php") {
    return $path;
    } else {
    return '/' . $url[1] . $path;
    }
    }
    

What just happened?

We added a simple function called form that serves as a wrapper around the $_POST array, which is an array of variables passed through the HTTP POST method. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required