简体   繁体   中英

how to pass multiple parameters in URL using slim micro framework

I've been following a tutorial on how to create a REST API using slim PHP framework. It's pretty simple and elaborate. But I've come across the problem which has led me into a whole new world. Here's my problem.. I'm creating users and each user can create a post and other users can comment or like the post here is the URL to create a comment POST->/v1/comment and i pass the "comment" as a parameter. That goes well. The Problem now is putting the comment under the particular post to which it belongs. For example, I want to do something like this

/v1/post/post_id/comment == /v1/post/4/comment(get all comments under post 4)
/v1/post/post_id/comment/comment_id == /v1/post/3/comment/12(get comment 12 from post 3)

How can i accomplish this.I've read about HATEOAS, but slim doesn't support it.Please correct me if i'm wrong.Here is a code fragment of my post which works well.

$app->post('/posts', 'authenticate', function() use ($app) {
     global $user_id;

    $db = new DbHandler();
      // 
           // check for required params
            verifyRequiredParams(array('post'));

            $response = array();
            $post = $app->request->post('post');




            // creating new post
            $post_id = $db->createPost($user_id, $post);

I don't want to pass the id's as parameters.I will appreciate any help.Thanks

i don't think you've done your research well enough.

<?php
$app = new \Slim\Slim();
$app->get('/books/:one/:two', function ($one, $two) {
    echo "The first parameter is " . $one;
    echo "The second parameter is " . $two;
});

That's a demo code gotten from http://www.slimframework.com/ which clearly illustrates passing multiple parameters to a url.I think thats what your looking for. Please take your time and go through the documentation in other to know more.Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM