[英]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. 我一直在遵循有关如何使用苗条的PHP框架创建REST API的教程。 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. 这是我的问题。我正在创建用户,每个用户可以创建一个帖子,其他用户可以评论,或者喜欢该帖子,这里是创建评论的URL
POST->/v1/comment and i pass the "comment"
作为参数。 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. 我该如何做到这一点。我已经阅读了有关HATEOAS的信息,但slim对此不提供支持。如果我写错了,请纠正我。这是我帖子的代码片段,效果很好。
$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 我不想将id作为参数传递,我将不胜感激。
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. 那是从http://www.slimframework.com/获得的演示代码,它清楚地说明了将多个参数传递给url。我认为这就是您想要的。 Please take your time and go through the documentation in other to know more.Good luck
请花点时间浏览其他文档以了解更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.