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 — creating a route and handling the creation of the Post

In order to actually create a post, we'll need to create a route and handle the form input.

  1. Open index.php.
  2. Create a basic post route, and call it post.
    post('/post', function($app) {
    });
    
  3. Inside our post route, let's accept the value of the passed value content and use the create function on our Post class to actually create the post. Once the post is created, we'll redirect the user back to their profile.
    post('/post', function($app) {
    $post = new Post();
    $post->content = $app->form('content');
    $post->create();
    $app->redirect('/user/' . User::current_user());
    
    });
    
  4. We've done quite a bit to make sure that the user is authenticated when creating a post, but let's triple check ...

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